Skip to content

Commit

Permalink
Document using jest to test
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Mar 15, 2015
1 parent 10f3864 commit 182f836
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/testing/stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,29 @@ describe('PetStore', () => {
});
});
```

If you're using jest to test it is advised you unmock your alt instance as well as alt itself.

You can set this up in your `package.json` like so:

```js
"jest": {
"unmockedModulePathPatterns": [
"../node_modules/alt",
"alt.js"
]
}
```

You can also test the dispatcher by overwriting `alt.dispatcher`. Here is an example:

```js
beforeEach(function() {
alt = require('../../alt');
alt.dispatcher = { register: jest.genMockFunction() };
UnreadThreadStore = require('../UnreadThreadStore');
callback = alt.dispatcher.register.mock.calls[0][0];
});
```

You can see a working jest test [here](https://github.com/goatslacker/alt/blob/master/examples/chat/js/stores/__tests__/UnreadThreadStore-test.js) which tests the [UnreadThreadStore](https://github.com/goatslacker/alt/blob/master/examples/chat/js/stores/UnreadThreadStore.js) from the [flux chat example](https://github.com/goatslacker/alt/tree/master/examples/chat) application.

0 comments on commit 182f836

Please sign in to comment.