Search code examples
typescriptts-mockito

ts-mockito mocked promise never resolves


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?


Solution

  • 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.