NagRock / ts-mockito

Mocking library for TypeScript
MIT License
977 stars 93 forks source link

Problem mocking interface #156

Open lfontana-schema31 opened 5 years ago

lfontana-schema31 commented 5 years ago

This doesn't work. promise is pending and it will not be resolved :(

interface ITest {
    f(): Promise<ITest>;
}

describe('test suite', () => {
    it('test', async () => {
        const mockedObj = m.mock<ITest>();
        m.when(mockedObj.f()).thenResolve(mockedObj);

        const istance = m.instance(mockedObj);
        const promise = istance.f();
        const res = await promise;

        expect(res).to.equal(mockedObj);

    });
});
NagRock commented 5 years ago

Thanks for reporting. I will take a look