Skip to content

Commit

Permalink
added replaceActionCreators, allow to specify configuration for the b…
Browse files Browse the repository at this point in the history
…abel plugin
  • Loading branch information
asvetliakov committed Feb 23, 2018
1 parent 7e5a083 commit 71e379f
Show file tree
Hide file tree
Showing 9 changed files with 3,570 additions and 4,611 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tslint.alwaysShowRuleFailuresAsWarnings": true,
"runCurrentTest.run": "npm run test -- ${relativeTestPath} --runTestsByPath --testNamePattern \"${fullTestName}\"",
"runCurrentTest.runAndUpdateSnapshots": "npm run test -- -u ${relativeTestPath} --runTestsByPath --testNamePattern \"${fullTestName}\""
"runCurrentTest.runAndUpdateSnapshots": "npm run test -- -u ${relativeTestPath} --runTestsByPath --testNamePattern \"${fullTestName}\"",
"typescript.tsdk": "node_modules/typescript/lib"
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## 1.2.0
- Allow to override default babel plugin configuration
- Added ```replaceActionCreators()``` which does the same as ```mockActionCreators()``` but doesn't try automock specified identifiers.

### 1.0.0-1.1.0
Initial release
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mock redux action creators with jest

## For what do you need it?
## Why

You're cool. You're going to test your React smart components (aka containers in redux) and make assumptions what they call necessary redux action creators. Well, you can have few ways to achieve this:

Expand Down Expand Up @@ -170,12 +170,13 @@ import { anotherAction } from "../anotherAction";

// Automatically mock your action creator modules. When using babel transformer it will insert jest.mock() for their module paths
mockActionCreators(myAction, anotherAction);
// or replaceActionCreators(myAction, anotherAction); // Doesn't insert jest.mock() for their module paths, expects myAction and anotherAction be already mocked (i.e. jest.fn())

const dispatch = jest.fn();
const wrapper = shallow(<C dispatch={dispatch} />);
wrapper.find("button").simulate("click");

// Pretty easy, isn't it?
// Pretty easy, isn't it?
expect(dispatch).toBeCalledWithActionCreator(anotherAction, "test");
expect(dispatch).not.toBeCalledWithActionCreator(myAction);

Expand All @@ -193,7 +194,7 @@ expect(dispatch).toBeCalledWithActionCreator(anotherAction, "test2");

```npm install jest-mock-action-creators --save-dev```

Add ```./node_modules/jest-mock-action-creators/babel``` to your plugins in .babelrc
Add ```jest-mock-action-creators/babel``` to your plugins in .babelrc or .babelrc.js

When using typescript and ```ts-jest```, enable babel processing in ```ts-jest``` (enabled by default) and tell it to use .babelrc:

Expand Down
Loading

0 comments on commit 71e379f

Please sign in to comment.