NagRock / ts-mockito

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

How to mock methods that are arrow functions #143

Open grischenko-v opened 5 years ago

grischenko-v commented 5 years ago

Try to test calling method width parameter,

export class TestArrowMockStore {
    test = (_value: number) => {};
}

describe('Mocking arrow function tests', () => {
    const store = mock(TestArrowMockStore);
    when(store.test(12)).thenReturn();

    const storeInstance = instance(store);

    test('store test', () => {
        storeInstance.test(12);
        verify(store.test(12)).once();
    });
});

but i get this:

Mocking arrow function tests › store test

    TypeError: storeInstance.test is not a function

      test('store test', () => {
          storeInstance.test(12);
                                       ^
          verify(store.test(12)).once();
  });
| });

What I do wrong?

mmarchois commented 4 years ago

Take a look at https://github.com/NagRock/ts-mockito/issues/171