Skip to content

Commit

Permalink
Create 36.test.ts (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcshaz authored and ffMathy committed Apr 3, 2019
1 parent 13be317 commit 319bcff
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/issues/36.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import test from 'ava';

import { Substitute, Arg } from '../../src/index';

interface IData { serverCheck: Date, data: { a: any[] } }
interface IFetch { getUpdates: (arg: Date | null) => Promise<IData> }

test('issue 36 - promises returning object with properties', async t => {
const emptyFetch = Substitute.for<IFetch>();
const now = new Date();
emptyFetch.getUpdates(null).returns(Promise.resolve<IData>({
serverCheck: now,
data: { a: [1] }
}));
const result = await emptyFetch.getUpdates(null);
t.true(result.serverCheck instanceof Date, 'given date is instanceof Date');
t.is(result.serverCheck, now, 'dates are the same');
t.true(Array.isArray(result.data.a), 'deep array isArray');
t.deepEqual(result.data.a, [1], 'arrays are deep equal');
});

0 comments on commit 319bcff

Please sign in to comment.