Skip to content

Commit 4183c0e

Browse files
committed
Fix sequence describe name
1 parent c284fef commit 4183c0e

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export class ReducerTestContext<S> {
2020
}
2121

2222
public snapshotAction(action: Action, payloadName?: string): void {
23-
const actionName = `${action.type}(${payloadName ||
24-
JSON.stringify(action.payload)})`;
25-
describe(actionName, () => {
23+
describe(this.actionName(action, payloadName), () => {
2624
it("matches snapshot", async () => {
2725
const store = this.makeStore(this.defaultState);
2826
await Promise.resolve(store.dispatch(action));
@@ -37,8 +35,11 @@ export class ReducerTestContext<S> {
3735
store.dispatch(action);
3836
return store.getState();
3937
});
40-
it("matches snapshot", () => {
41-
expect(states).toMatchSnapshot();
38+
const actionNames = actions.map(action => this.actionName(action));
39+
describe(`(sequence) ${actionNames}`, () => {
40+
it("matches snapshot", () => {
41+
expect(states).toMatchSnapshot();
42+
});
4243
});
4344
}
4445

@@ -53,6 +54,10 @@ export class ReducerTestContext<S> {
5354
expect(this.defaultState).toMatchSnapshot();
5455
});
5556
}
57+
58+
private actionName(action: Action, payloadName?: string) {
59+
return `${action.type}(${payloadName || JSON.stringify(action.payload)})`;
60+
}
5661
}
5762

5863
export default function reducerTest<S>(

test/__snapshots__/index.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`reducer SET_A("other a") matches snapshot 1`] = `
4-
Object {
5-
"a": "other a",
6-
"d": 0,
7-
}
8-
`;
9-
10-
exports[`reducer matches snapshot 1`] = `
3+
exports[`reducer (sequence) SET_B({"c":true}),SET_A("some other") matches snapshot 1`] = `
114
Array [
125
Object {
136
"a": "a",
@@ -25,3 +18,10 @@ Array [
2518
},
2619
]
2720
`;
21+
22+
exports[`reducer SET_A("other a") matches snapshot 1`] = `
23+
Object {
24+
"a": "other a",
25+
"d": 0,
26+
}
27+
`;

test/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import reducer, {setA, setB } from "./reducer";
22
import reducerTest from "../src/index";
33

44
describe("reducer", reducerTest(reducer)(function () {
5+
this.expectInitialState({ a: "a", d: 0 });
56
this.snapshotAction(setA("other a"));
67
this.snapshotActionSequence(setB({ c: true }), setA("some other"));
78
}));

test/reducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export default function reducer(state: State = DEFAULT_STATE, action: Action): S
2323
return { ...state, b: action.payload };
2424
case "SET_D":
2525
return { ...state, d: action.payload };
26+
default:
27+
return state;
2628
}
2729
}
2830

0 commit comments

Comments
 (0)