diff --git a/spec/issues/36.test.ts b/spec/issues/36.test.ts new file mode 100644 index 0000000..4fa4a29 --- /dev/null +++ b/spec/issues/36.test.ts @@ -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 } + +test('issue 36 - promises returning object with properties', async t => { + const emptyFetch = Substitute.for(); + const now = new Date(); + emptyFetch.getUpdates(null).returns(Promise.resolve({ + 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'); +});