ts-mockito mocked promise never resolves

1.6k Views Asked by At

given this

beforeAll(() => {
  testContainer.register(Beans.CEC_LOCATION, {
    useFactory: (c) => {
      const contextMock = mock<ContentfulEntryContext<ContentfulLocationFields>>();
      const entryMock = mock<Entry<ContentfulLocationFields>>();
      when(entryMock.fields).thenReturn({
        id: '42',
        name: 'Deep Mind',
      });
      when(contextMock.get()).thenResolve(instance(entryMock));
      const location = (id: string) => {
        return instance(contextMock);
      };
      location('42').get().then((v) => console.log(v));
      return location;
    },
  });
});

when location.get() is called, then never resolves, even on a 60s timeout, reject seems to work. What am I doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

That is a bug in the ts-mockito library itself (issue #191).
A pull request is on it's way, so hopefully it will be fixed soon.
Currently, at version 2.6.1, it is still there.