stubbing a function using jest

后端 未结 3 1649
一生所求
一生所求 2021-02-05 03:49

is there a way to stub a function using jest API? I\'m used to working with sinon stub, where I can write unit-tests with stubs for any function call coming out of my tested un

3条回答
  •  我在风中等你
    2021-02-05 04:07

    Jest provides jest.fn(), which has some basic mocking and stubbing functionality.

    If you're experienced and comfortable with sinon you could still create Jest-based tests which use sinon test doubles. However you'll lose the convenience of built in Jest matchers such as expect(myStubFunction).toHaveBeenCalled().

提交回复
热议问题