# Jest

## Spying in automaitc `node_module` mocks

When you want to spy on methods of a module that was automatically mocked (via a file in the `__mocks__` folder that was named after the module), jest will complain. To be able to do so, you can export the functions you want to spy on from said file.

Following is an exmple of a mock for `react-native-keychain`:

```javascript
// __mocks__/react-native-keychain.js
export const setInternetCredentials = jest.fn()
export const getInternetCredentials = jest.fn()
```

This would allow us to do something like `expect(Keychain.setInternetCredentials).toHaveBeenCalledTimes(1)`

**Note:** `react-native-keychain` does not have a default export. This is why we are exporting seperate `const`s here. For a module with a default export, we would have to adapt accordingly.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.christianpoplawski.de/javascript/jest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
