generated from iamogbz/node-js-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,47 @@ | ||
import { bindActionCreators } from "src/utils/bindActionCreators"; | ||
|
||
describe("bindActionCreators", () => { | ||
it("binds action creator function to dispatch", () => { | ||
const dispatch = jest.fn(); | ||
const action = { type: "ACTION_TYPE", payload: "Some payload" }; | ||
const boundActionCreator = bindActionCreators(() => action, dispatch); | ||
expect(boundActionCreator()).toBeUndefined(); | ||
expect(dispatch).toHaveBeenCalledTimes(1); | ||
expect(dispatch).toHaveBeenCalledWith(action); | ||
}); | ||
|
||
it("binds action creator mapping to dispatch", () => { | ||
const dispatch = jest.fn(); | ||
const action = { type: "ACTION_TYPE", payload: "Some payload" }; | ||
const boundActionCreators = bindActionCreators( | ||
({ | ||
action1: () => action, | ||
action2: null, | ||
action3: undefined, | ||
action4: "non function", | ||
} as unknown) as ActionCreatorMapping, | ||
dispatch, | ||
); | ||
expect(boundActionCreators.action1()).toBeUndefined(); | ||
expect(dispatch).toHaveBeenCalledTimes(1); | ||
expect(dispatch).toHaveBeenCalledWith(action); | ||
expect(boundActionCreators.action2).toBeUndefined(); | ||
expect(boundActionCreators.action3).toBeUndefined(); | ||
expect(boundActionCreators.action4).toBeUndefined(); | ||
}); | ||
|
||
it.each` | ||
actionCreator | ||
${"non function"} | ||
${null} | ||
${undefined} | ||
`( | ||
"does not binds unsupported action creator to dispatch", | ||
({ actionCreator }) => { | ||
const dispatch = jest.fn(); | ||
expect(() => bindActionCreators(actionCreator, dispatch)).toThrow( | ||
"bindActionCreators expected an object or a function", | ||
); | ||
}, | ||
); | ||
}); |