-
Couldn't load subscription status.
- Fork 11
Add support for jasmine 2.x #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6d89a4b
Add support for jasmine 2.x
giuband 50a1bf0
Add tests with jasmine as a step in npm test
giuband 8b908f8
Add support for negativeCompare, use function syntax
giuband f16cb94
Add tests for negativeCompare
giuband f63c61e
Update readme, add documentation for usage with jasmine
giuband File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # [jasmine](https://github.com/jasmine/jasmine) | ||
|
|
||
| ## Registration | ||
|
|
||
| ```js | ||
| // using ES6 modules | ||
| import { registerAssertions } from 'redux-actions-assertions/jasmine'; | ||
|
|
||
| // using CommonJS modules | ||
| var registerAssertions = require('redux-actions-assertions/jasmine').registerAssertions; | ||
|
|
||
| // registration | ||
| beforeEach(registerAssertions); | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### .toDispatchActions | ||
|
|
||
| > `expect(action).toDispatchActions(expectedActions, done)` | ||
|
|
||
| Asserts that when given `action` is dispatched it will dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions. | ||
|
|
||
| ```js | ||
| expect(myActionCreator()) | ||
| .toDispatchActions({ type: 'MY_ACTION_START' }, done); | ||
| ``` | ||
|
|
||
| ### .not.toDispatchActions | ||
|
|
||
| > `expect(action).not.toDispatchActions(expectedActions, done)` | ||
|
|
||
| Asserts that when given `action` is dispatched it will not dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions. | ||
|
|
||
| ```js | ||
| expect(myActionCreator()) | ||
| .not.toDispatchActions({ type: 'MY_ACTION_START' }, done); | ||
| ``` | ||
|
|
||
| ### .toDispatchActionsWithState | ||
|
|
||
| > `expect(action).toDispatchActionsWithState(state, expectedActions, done)` | ||
|
|
||
| Asserts that store initialised with `state` before `action` is dispatched. | ||
|
|
||
| ```js | ||
| const state = {property: 'value'}; | ||
| const expectedActions = [{ type: 'MY_ACTION_START' }, finishActionCreator()]; | ||
| expect(myActionCreator()) | ||
| .toDispatchActionsWithState(state, expectedActions, done); | ||
| ``` | ||
| You can also use it with `.not`: | ||
|
|
||
| ```js | ||
| expect(myActionCreator()) | ||
| .not.toDispatchActionsWithState(state, expectedActions, done); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* eslint-env jasmine */ | ||
| import { assertions } from 'redux-actions-assertions-js'; | ||
|
|
||
| function toDispatchActions() { | ||
| return { | ||
| compare(action, expectedActions, done) { | ||
| assertions.toDispatchActions(action, expectedActions, done, done.fail); | ||
| return { pass: true }; | ||
| }, | ||
| negativeCompare(action, expectedActions, done) { | ||
| assertions.toNotDispatchActions(action, expectedActions, done, done.fail); | ||
| return { pass: true }; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function toNotDispatchActions() { | ||
| return { | ||
| compare(action, expectedActions, done) { | ||
| assertions.toNotDispatchActions(action, expectedActions, done, done.fail); | ||
| return { pass: true }; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function toDispatchActionsWithState() { | ||
| return { | ||
| compare(action, state, expectedActions, done) { | ||
| assertions.toDispatchActionsWithState(state, action, expectedActions, done, done.fail); | ||
| return { pass: true }; | ||
| }, | ||
| negativeCompare(action, state, expectedActions, done) { | ||
| assertions.toNotDispatchActionsWithState(state, action, expectedActions, done, done.fail); | ||
| return { pass: true }; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function toNotDispatchActionsWithState() { | ||
| return { | ||
| compare(action, state, expectedActions, done) { | ||
| assertions.toNotDispatchActionsWithState(state, action, expectedActions, done, done.fail); | ||
| return { pass: true }; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| const matchers = { | ||
| toDispatchActions, | ||
| toNotDispatchActions, | ||
| toDispatchActionsWithState, | ||
| toNotDispatchActionsWithState | ||
| }; | ||
|
|
||
| function registerAssertions() { | ||
| jasmine.addMatchers(matchers); | ||
| } | ||
|
|
||
| export { | ||
| registerAssertions, | ||
| matchers | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* eslint-env jasmine */ | ||
| import thunk from 'redux-thunk'; | ||
| import { registerMiddlewares } from '../../src'; | ||
| import { registerAssertions } from '../../src/jasmine'; | ||
| import actions from '../testingData/actions'; | ||
|
|
||
| registerMiddlewares([thunk]); | ||
|
|
||
| beforeEach(registerAssertions); | ||
|
|
||
| describe('jasmine', () => { | ||
| describe('toDispatchActionsWithState', () => { | ||
| it('should accept object', (done) => { | ||
| const state = { property: 'value' }; | ||
| expect(actions.actionCreatorWithGetState()) | ||
| .toDispatchActionsWithState(state, actions.actionWithGetState({ property: 'value' }), done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.toDispatchActions', () => { | ||
| it('should accept single action', (done) => { | ||
| expect(actions.start()).toDispatchActions(actions.start(), done); | ||
| }); | ||
|
|
||
| it('should accept array with one action', (done) => { | ||
| expect(actions.start()).toDispatchActions([actions.start()], done); | ||
| }); | ||
|
|
||
| it('should accept array with multiple actions', (done) => { | ||
| expect(actions.asyncActionCreator()) | ||
| .toDispatchActions(actions.expectedActions, done); | ||
| }); | ||
|
|
||
| it('should accept array with nested async action creators', (done) => { | ||
| expect(actions.parentAsyncActionCreator()) | ||
| .toDispatchActions(actions.expectedParentActions, done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.toNotDispatchActions', () => { | ||
| it('should accept single action', (done) => { | ||
| expect(actions.start()).toNotDispatchActions(actions.anotherStart(), done); | ||
| }); | ||
|
|
||
| it('should accept array with one action', (done) => { | ||
| expect(actions.start()).toNotDispatchActions([actions.anotherStart()], done); | ||
| }); | ||
|
|
||
| it('should accept array with multiple actions', (done) => { | ||
| expect(actions.asyncActionCreator()) | ||
| .toNotDispatchActions(actions.anotherExpectedActions, done); | ||
| }); | ||
|
|
||
| it('should accept array with nested async action creators', (done) => { | ||
| expect(actions.parentAsyncActionCreator()) | ||
| .toNotDispatchActions(actions.anotherParentExpectedActions, done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.not.toDispatchActions', () => { | ||
| it('should accept single action', (done) => { | ||
| expect(actions.start()).not.toDispatchActions(actions.anotherStart(), done); | ||
| }); | ||
|
|
||
| it('should accept array with one action', (done) => { | ||
| expect(actions.start()).not.toDispatchActions([actions.anotherStart()], done); | ||
| }); | ||
|
|
||
| it('should accept array with multiple actions', (done) => { | ||
| expect(actions.asyncActionCreator()) | ||
| .not.toDispatchActions(actions.anotherExpectedActions, done); | ||
| }); | ||
|
|
||
| it('should accept array with nested async action creators', (done) => { | ||
| expect(actions.parentAsyncActionCreator()) | ||
| .not.toDispatchActions(actions.anotherParentExpectedActions, done); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "spec_dir": "test/jasmine", | ||
| "spec_files": [ | ||
| "*.js" | ||
| ], | ||
| "helpers": [ | ||
| "../../node_modules/babel-register/lib/node.js" | ||
| ] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to expose
matchers?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to import them from Jest and making the registration step more explicit on the jest's
setupTestFrameworkScriptFilefile (instead of simply calling jasmine'sregisterAssertions()there)