Skip to content

Commit 319bcff

Browse files
mcshazffMathy
authored andcommitted
Create 36.test.ts (#40)
1 parent 13be317 commit 319bcff

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

spec/issues/36.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import test from 'ava';
2+
3+
import { Substitute, Arg } from '../../src/index';
4+
5+
interface IData { serverCheck: Date, data: { a: any[] } }
6+
interface IFetch { getUpdates: (arg: Date | null) => Promise<IData> }
7+
8+
test('issue 36 - promises returning object with properties', async t => {
9+
const emptyFetch = Substitute.for<IFetch>();
10+
const now = new Date();
11+
emptyFetch.getUpdates(null).returns(Promise.resolve<IData>({
12+
serverCheck: now,
13+
data: { a: [1] }
14+
}));
15+
const result = await emptyFetch.getUpdates(null);
16+
t.true(result.serverCheck instanceof Date, 'given date is instanceof Date');
17+
t.is(result.serverCheck, now, 'dates are the same');
18+
t.true(Array.isArray(result.data.a), 'deep array isArray');
19+
t.deepEqual(result.data.a, [1], 'arrays are deep equal');
20+
});

0 commit comments

Comments
 (0)