@@ -7,65 +7,19 @@ It use [redux-mock-store](https://github.com/arnaudbenard/redux-mock-store) to m
77[ ![ build status] ( https://img.shields.io/travis/dmitry-zaets/redux-actions-assertions/master.svg?style=flat-square )] ( https://travis-ci.org/dmitry-zaets/redux-actions-assertions )
88[ ![ npm version] ( https://img.shields.io/npm/v/redux-actions-assertions.svg?style=flat-square )] ( https://www.npmjs.com/package/redux-actions-assertions )
99
10- ## What it does:
11- - [ Simplifies initial setup] ( #simplifies-initial-setup ) ;
12- - [ Reduces repetitive code of test methods] ( #reduces-repetitive-code-of-test-methods ) ;
13- - [ Allows to avoid re-testing nested action creators] ( #allows-to-avoid-re-testing-nested-action-creators ) ;
14-
1510## Supported Assertion Frameworks/Libraries:
16- - [ chai] ( #chai )
17- - [ expect] ( #expect )
18- - [ expect.js] ( #expectjs )
19- - [ should] ( #should )
11+ - [ chai] ( http://dmitry.js.org/redux-actions-assertions/chai.html )
12+ - [ expect] ( http://dmitry.js.org/redux-actions-assertions/expect.html )
13+ - [ expect.js] ( http://dmitry.js.org/redux-actions-assertions/expectjs.html )
14+ - [ should] ( http://dmitry.js.org/redux-actions-assertions/should.html )
15+ - [ pure javascript assertion] ( http://dmitry.js.org/redux-actions-assertions/javascript.html )
2016
21- If you have not found assertion framework/library that you are using - you can use [ pure javascript assertion ] ( #javascript ) or create an issue .
17+ If you have not found assertion framework/library that you are using - please add comment into [ this issue ] ( https://github.com/dmitry-zaets/redux-actions-assertions/issues/3 ) .
2218
23- ### Simplifies initial setup
24- It provides singe-time global configuration for middlewares and initial store state.
25-
26- Without:
27- ``` javascript
28- const middlewares = [thunk];
29- const mockStore = configureStore (middlewares);
30- const store = mockStore ({ /* initial store object*});
31- ```
32- With:
33- ```javascript
34- registerMiddlewares([ thunk ]);
35- // to set custom initial state
36- registerInitialStoreState(/*object of function*/ );
37- // to generate initial state of your application
38- registerInitialStoreState (buildInitialStoreState (/* your root reducer*/ ));
39- ` ` `
40-
41- ### Reduces repetitive code of test methods
42- It reduces boilerplate of test methods and makes testing fluent.
43-
44- Without:
45- ` ` ` javascript
46- const store = mockStore (/* initial state */ );
47- const expectedActions = [
48- { type: types .FETCH_TODOS_REQUEST },
49- /* All expected triggered action objects */
50- ];
51- store .dispatch (fetchData ()).then (() => {
52- const actions = store .getActions ();
53- expect (actions).toEqual (expectedActions);
54- }).then (done).catch (done);
55- ` ` `
56-
57- With:
58- ` ` ` javascript
59- const expectedActions = [
60- /* All expected triggered action objects or action creator functions*/
61- ];
62- expect (fetchData ()).toDispatchActions (expectedActions, done);
63- ` ` `
64-
65- With using customised store state:
66- ` ` ` javascript
67- expect (fetchData ()).withState ({/* custom state*/ }).toDispatchActions (expectedActions, done);
68- ` ` `
19+ ## What it does:
20+ - [ Allows to avoid retesting nested action creators] ( #allows-to-avoid-retesting-nested-action-creators ) ;
21+ - [ Reduces repetitive code of test methods] ( #reduces-repetitive-code-of-test-methods ) ;
22+ - [ Simplifies initial setup] ( #simplifies-initial-setup ) ;
6923
7024### Allows to avoid re-testing nested action creators
7125It allows to test only actions that need to be tested.
@@ -125,6 +79,53 @@ expect(actionA()).withState({ todos: [] }).toDispatch([
12579], done);
12680```
12781
82+ ### Reduces repetitive code of test methods
83+ It reduces boilerplate of test methods and makes testing fluent.
84+
85+ Without:
86+ ``` javascript
87+ const store = mockStore (/* initial state */ );
88+ const expectedActions = [
89+ { type: types .FETCH_TODOS_REQUEST },
90+ /* All expected triggered action objects */
91+ ];
92+ store .dispatch (fetchData ()).then (() => {
93+ const actions = store .getActions ();
94+ expect (actions).toEqual (expectedActions);
95+ }).then (done).catch (done);
96+ ```
97+
98+ With:
99+ ``` javascript
100+ const expectedActions = [
101+ /* All expected triggered action objects or action creator functions*/
102+ ];
103+ expect (fetchData ()).toDispatchActions (expectedActions, done);
104+ ```
105+
106+ With using customised store state:
107+ ``` javascript
108+ expect (fetchData ()).withState ({/* custom state*/ }).toDispatchActions (expectedActions, done);
109+ ```
110+
111+ ### Simplifies initial setup
112+ It provides singe-time global configuration for middlewares and initial store state.
113+
114+ Without:
115+ ``` javascript
116+ const middlewares = [thunk];
117+ const mockStore = configureStore (middlewares);
118+ const store = mockStore ({ /* initial store object*});
119+ ```
120+ With:
121+ ```javascript
122+ registerMiddlewares([ thunk ]);
123+ // to set custom initial state
124+ registerInitialStoreState(/*object of function*/ );
125+ // to generate initial state of your application
126+ registerInitialStoreState (buildInitialStoreState (/* your root reducer*/ ));
127+ ` ` `
128+
128129## Installation
129130
130131Using [npm](https://www.npmjs.org/):
@@ -170,247 +171,4 @@ var registerInitialStoreState = reduxActionsAssertions.registerInitialStoreState
170171
171172// registration
172173registerInitialStoreState (buildInitialStoreState (/* root reducer function */ ));
173- ` ` `
174-
175- ## javascript
176-
177- ### Registration
178-
179- For plain javasript assertions you dont need to register anything. Just import assertions in your tests:
180-
181- ` ` ` js
182- // using ES6 modules
183- import assertions from ' redux-actions-assertions/assertions' ;
184-
185- // using CommonJS modules
186- var assertions = require (' redux-actions-assertions/assertions' );
187-
188- // in test
189- assertions .toDispatchActions (/* */ )
190- assertions .toDispatchActionsWithState (/* */ );
191- ` ` `
192-
193- ### Usage
194-
195- #### toDispatchActions
196- > ` toDispatchActions (action, expectedActions, callback)`
197-
198- Asserts that when given ` action` is dispatched it will dispatch ` expectedActions` . ` action` can be a plain object (action) or a function (action creator). ` expectedActions` can be can be a plain object (action), a function (action creator), or an array of objects/functions.
199-
200- ` ` ` js
201- toDispatchActions (testActionCreator (), [{ type: ' MY_ACTION_START' }], callback);
202- ` ` `
203-
204- #### toDispatchActionsWithState
205-
206- > ` toDispatchActionsWithState (initialState, action, expectedActions, callback)`
207-
208- Same as ` toDispatchActions` + asserts that store initialised with ` state` before ` action` is dispatched.
209-
210- ` ` ` js
211- toDispatchActions ({property: ' value' }, testActionCreator (), [{ type: ' MY_ACTION_START' }], callback);
212- ` ` `
213-
214- ## [chai](https://github.com/chaijs/chai)
215-
216- ### Registration
217-
218- ` ` ` js
219- // using ES6 modules
220- import { registerAssertions } from ' redux-actions-assertions/chai' ;
221-
222- // using CommonJS modules
223- var registerAssertions = require (' redux-actions-assertions/chai' ).registerAssertions ;
224-
225- // registration
226- registerAssertions ();
227- ` ` `
228-
229- #### .to.dispatch.actions or assert.isDispatching
230-
231- > ` expect (action).to .dispatch .actions (expectedActions, callback)`
232-
233- > ` action .should .dispatch .actions (expectedActions, callback)`
234-
235- > ` assert .isDispatching (action, expectedActions, callback)`
236-
237- Asserts that when given ` action` is dispatched it will dispatch ` expectedActions` . ` action` can be a plain object (action) or a function (action creator). ` expectedActions` can be can be a plain object (action), a function (action creator), or an array of objects/functions.
238-
239- ` ` ` js
240- expect (myActionCreator ())
241- .to .dispatch .actions ({ type: ' MY_ACTION_START' }, callback);
242-
243- myActionCreator ()
244- .should .dispatch .actions ({ type: ' MY_ACTION_START' }, callback);
245-
246- assert .isDispatching (
247- myActionCreator (),
248- { type: ' MY_ACTION_START' },
249- callback
250- );
251- ` ` `
252-
253- #### .with.state or assert.isDispatchingWithState
254-
255- > ` expect (action).with .state (state).to .dispatch .actions (expectedActions, callback)`
256-
257- > ` action .should .with .state (state).dispatch .actions (expectedActions, callback)`
258-
259- > ` assert .isDispatchingWithState (action, expectedActions, state, callback)`
260-
261- Asserts that store initialised with ` state` before ` action` is dispatched.
262- ` ` ` js
263- expect (myActionCreator ())
264- .with .state ({ property: ' value' })
265- .to .dispatch .actions ([{ type: ' MY_ACTION_START' }, finishActionCreator ()], callback);
266-
267- myActionCreator ()
268- .should .with .({ property: ' value' })
269- .dispatch .actions ([{ type: ' MY_ACTION_START' }, finishActionCreator ()], callback);
270-
271- assert .isDispatchingWithState (
272- myActionCreator (),
273- [{ type: ' MY_ACTION_START' }, finishActionCreator ()],
274- { property: ' value' }
275- callback
276- );
277- ` ` `
278-
279- ## [expect](https://github.com/mjackson/expect)
280-
281- ### Registration
282-
283- ` ` ` js
284- // using ES6 modules
285- import { registerAssertions } from ' redux-actions-assertions/expect' ;
286-
287- // using CommonJS modules
288- var registerAssertions = require (' redux-actions-assertions/expect' ).registerAssertions ;
289-
290- // registration
291- registerAssertions ();
292- ` ` `
293- ### Usage
294-
295- #### .toDispatchActions
296-
297- > ` expect (action).toDispatchActions (expectedActions, callback)`
298-
299- Asserts that when given ` action` is dispatched it will dispatch ` expectedActions` . ` action` can be a plain object (action) or a function (action creator). ` expectedActions` can be can be a plain object (action), a function (action creator), or an array of objects/functions.
300-
301- ` ` ` js
302- expect (myActionCreator ())
303- .toDispatchActions ({ type: ' MY_ACTION_START' }, callback);
304- ` ` `
305-
306- #### .withState
307-
308- > ` expect (action).withState (state).toDispatchActions (expectedActions, callback)`
309-
310- Asserts that store initialised with ` state` before ` action` is dispatched.
311-
312- ` ` ` js
313- expect (myActionCreator ())
314- .withState ({property: ' value' })
315- .toDispatchActions ([{ type: ' MY_ACTION_START' }, finishActionCreator ()], callback);
316- ` ` `
317-
318- ## [expect.js](https://github.com/Automattic/expect.js)
319-
320- ### Registration
321-
322- ` ` ` js
323- // using ES6 modules
324- import { registerAssertions } from ' redux-actions-assertions/expectjs' ;
325-
326- // using CommonJS modules
327- var registerAssertions = require (' redux-actions-assertions/expectjs' ).registerAssertions ;
328-
329- // registration
330- registerAssertions ();
331- ` ` `
332-
333- ### Usage
334-
335- #### .dispatchActions
336-
337- > ` expect (action).to .dispatchActions (expectedActions, callback)`
338-
339- Asserts that when given ` action` is dispatched it will dispatch ` expectedActions` . ` action` can be a plain object (action) or a function (action creator). ` expectedActions` can be can be a plain object (action), a function (action creator), or an array of objects/functions.
340-
341- ` ` ` js
342- expect (myActionCreator ())
343- .to .dispatchActions ({ type: ' MY_ACTION_START' }, callback);
344- ` ` `
345-
346- #### .withState
347-
348- > ` expect (action).withState (state).to .dispatchActions (expectedActions, callback)`
349-
350- Asserts that store initialised with ` state` before ` action` is dispatched.
351-
352- ` ` ` js
353- expect (myActionCreator ())
354- .withState ({ property: ' value' })
355- .to .dispatchActions ([{ type: ' MY_ACTION_START' }, finishActionCreator ()], callback);
356- ` ` `
357-
358- ## [should](https://github.com/shouldjs/should.js)
359-
360- ### Registration
361-
362- ` ` ` js
363- // using ES6 modules
364- import { registerAssertions } from ' redux-actions-assertions/should' ;
365-
366- // using CommonJS modules
367- var registerAssertions = require (' redux-actions-assertions/should' ).registerAssertions ;
368-
369- // registration
370- registerAssertions ();
371- ` ` `
372-
373- ### Usage
374-
375- #### .dispatchActions
376-
377- > ` should (action).dispatchActions (expectedActions, callback)`
378- > ` action .should .dispatchActions (expectedActions, callback)`
379-
380- Asserts that when given ` action` is dispatched it will dispatch ` expectedActions` . ` action` can be a plain object (action) or a function (action creator). ` expectedActions` can be can be a plain object (action), a function (action creator), or an array of objects/functions.
381-
382- ` ` ` js
383- should (myActionCreator ())
384- .dispatchActions ({ type: ' MY_ACTION_START' }, callback);
385-
386- myActionCreator ().should
387- .dispatchActions ({ type: ' MY_ACTION_START' }, callback);
388- ` ` `
389-
390- #### .withState or with.state
391-
392- > ` should (action).withState (state).dispatchActions (expectedActions, callback)`
393- > ` should (action).with .state (state).dispatchActions (expectedActions, callback)`
394-
395- > ` action .should .withState (state).dispatchActions (expectedActions, callback)`
396- > ` action .should .with .state (state).dispatchActions (expectedActions, callback)`
397-
398- Asserts that store initialised with ` state` before ` action` is dispatched.
399-
400- ` ` ` js
401- should (myActionCreator ())
402- .withState ({ property: ' value' })
403- .dispatchActions ({ type: ' MY_ACTION_START' }, callback);
404-
405- should (myActionCreator ())
406- .with .state ({ property: ' value' })
407- .dispatchActions ({ type: ' MY_ACTION_START' }, callback);
408-
409- myActionCreator ().should
410- .withState ({ property: ' value' })
411- .dispatchActions ({ type: ' MY_ACTION_START' }, callback);
412-
413- myActionCreator ().should
414- .with .state ({ property: ' value' })
415- .dispatchActions ({ type: ' MY_ACTION_START' }, callback);
416- ` ` `
174+ ` ` `
0 commit comments