ike18t / ts-mockery

Simple type-safe typescript mocking library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Calling Mock.all<T>() on an interface breaks tests

pzaj2 opened this issue · comments

It turns out that calling it on any interface that only has properties and no functions will result in the same issue. Potentially it'll break on all interfaces whatsoever.

PREVIOUS CONTENT

There's a problem with Mock.All<T>() call when T is map-like interface. It'll break the tests (they'll timeout).

How to reproduce:

interface MapLike {
    [key: string]: any;
}
test('some test', async (done) => {
    const mockedData = Mock.All<MapLike>();
    const x = jest.fn();
    x.mockResolvedValue(mockedData);

    const result = await x();

    done();
});

I'm not sure it breaks on sync calls too.

This can be mitigated by replacing Mock.all with Mock.of.

Worth sorting it out nonetheless I think, I've spent a great deal of time trying to find out what's wrong. Perhaps instead of looking for a potential fix the docs could be amended to make note of that.

Hi @pzaj2

Thanks for opening this issue! I'll try to replicate this and see if it can be fixed, otherwise I'll make the documentation update like you suggested.

@pzaj2 I opened a PR that should resolve this issue if you'd like to check it out. Not super stoked about the solution but it does resolve the issue.