> For the complete documentation index, see [llms.txt](https://notes.lirenxn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.lirenxn.com/2019-1/wk-notes-11-18-jest-mock.md).

# Wk-notes-11-18-jest-mock

### **jest api**

* `jest.fn()` function spy, can track how many times the function being called
* `jest.mock()` can mock a module as imports

```javascript
jest.mock('./LivePricingActions', () => ({
  resetLivePricingData: jest.fn(),
  fetchOneWayPrices: jest.fn(),
  fetchReturnPrices: jest.fn(),
  updateFlightSegment: jest.fn()
}));
```

**\[!! Once a module is mocked]:** If an exported function in that module is invoked sometime in the test, it **MUST** be mocked as a `jest.fn()`. Otherwise, the function will not be found.
