Skip to content

Commit

Permalink
added a jest example (yeahoffline#146)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Janowski <kamil.janowski@mavericks.fi>
  • Loading branch information
kamiljano and Kamil Janowski authored Nov 18, 2020
1 parent 2365a7f commit 3b2e8a4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,31 @@ redis-mock is work in progress, feel free to report an issue
* 0.4.7 update devDependencies (should, mocha)


# Example usage

## Jest

In order to make sure that your tests use the `redis-mock` instead of the actual `redis` implementation,
update your `jest.config.js`, by adding `setupFileAfterEnv`, as follows:

```javascript
module.exports = {
// other properties...
setupFilesAfterEnv: ['./jest.setup.redis-mock.js'],
};
```

From this point on, jest will always trigger the content of `jest.setup.redis-mock.js` before the execution of all tests.

Now, let's create the file `jest.setup.redis-mock.js` in the same directory as `jest.config.js` and paste the following
content:

```javascript
jest.mock('redis', () => jest.requireActual('redis-mock'));
```

This will make sure that the actual `redis` is never loaded and whenever any file tries to import/require `redis`,
`redis-mock` will be returned instead.

## LICENSE - "MIT License"

Expand Down

0 comments on commit 3b2e8a4

Please sign in to comment.