Skip to content

Commit 295169d

Browse files
committed
WIP Pending bug tests
1 parent 3ccf11f commit 295169d

4 files changed

Lines changed: 83 additions & 15 deletions

File tree

__tests__/wrappers/withAsyncActions.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ describe('With Async Client HOC', () => {
419419
const ComponentWithMetaHandler = withAsyncActions({
420420
firstAction: firstAction.withSuccessHandler(({ action }) => action()),
421421
secondAction: secondAction.withErrorHandler(({ action }) => action()),
422-
thirdAction: thirdAction.withPendingHandler(({ action }) => action())
422+
thirdAction: thirdAction.withPendingHandler((props, action) => props.action(props, action))
423423
})(Component);
424424

425425
const { wrapper } = setupComponent(ComponentWithMetaHandler);
@@ -452,6 +452,23 @@ describe('With Async Client HOC', () => {
452452
component.props().thirdAction.dispatch(defer.promise);
453453

454454
defer.resolve();
455+
expect(component.props().action).lastCalledWith(
456+
expect.objectContaining({
457+
thirdAction: expect.objectContaining({
458+
meta: expect.objectContaining({
459+
pending: true,
460+
success: false,
461+
error: false,
462+
}),
463+
})
464+
}),
465+
expect.objectContaining({
466+
requestAction: expect.objectContaining({
467+
payload: expect.anything(),
468+
})
469+
})
470+
);
471+
455472
await defer.promise.then();
456473

457474
expect(component.props().action).toHaveBeenCalledTimes(3);

__tests__/wrappers/withAsyncHandlers.spec.js

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,38 @@ describe('Async Client withHandlers HOC', () => {
7070
await defer.promise.then();
7171

7272
expect(successHandler).toHaveBeenCalledTimes(1);
73+
expect(successHandler).lastCalledWith(
74+
expect.objectContaining({
75+
action: expect.objectContaining({
76+
meta: expect.objectContaining({
77+
pending: false,
78+
success: true,
79+
error: false,
80+
}),
81+
})
82+
}),
83+
expect.objectContaining({
84+
requestAction: expect.objectContaining({
85+
payload: expect.anything(),
86+
})
87+
})
88+
);
89+
});
90+
91+
it('should handle withPendingHandler()', async () => {
92+
expect(pendingHandler).toHaveBeenCalledTimes(1);
93+
expect(pendingHandler).lastCalledWith(
94+
expect.objectContaining({
95+
action: expect.objectContaining({
96+
meta: expect.objectContaining({
97+
pending: true,
98+
success: false,
99+
error: false,
100+
}),
101+
})
102+
}),
103+
expect.anything()
104+
);
73105
});
74106

75107
it('should handle withErrorHandler()', async () => {
@@ -81,13 +113,25 @@ describe('Async Client withHandlers HOC', () => {
81113
await defer.promise.catch();
82114
} catch(e) {
83115
expect(errorHandler).toHaveBeenCalledTimes(1);
116+
expect(errorHandler).lastCalledWith(
117+
expect.objectContaining({
118+
action: expect.objectContaining({
119+
meta: expect.objectContaining({
120+
pending: false,
121+
success: false,
122+
error: expect.anything(),
123+
}),
124+
})
125+
}),
126+
expect.objectContaining({
127+
requestAction: expect.objectContaining({
128+
payload: expect.anything(),
129+
})
130+
})
131+
);
84132
}
85133
});
86134

87-
it('should handle withPendingHandler()', async () => {
88-
expect(pendingHandler).toHaveBeenCalledTimes(2);
89-
});
90-
91135
it('should pass action to handler', async () => {
92136
component.props().action.dispatch('action_payload');
93137
expect(pendingHandler).lastCalledWith(
@@ -98,7 +142,7 @@ describe('Async Client withHandlers HOC', () => {
98142
})
99143
})
100144
);
101-
})
145+
});
102146
});
103147

104148
describe('withAsyncHandlers({ metaHandler })', () => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"ramda": "^0.26.1",
3232
"react": "^16.8.6",
3333
"react-dom": "^16.8.6",
34-
"react-redux": "^6.0.1",
34+
"react-redux": "^7.0.3",
3535
"react-test-renderer": "^16.8.6",
3636
"redux": "^4.0.1",
3737
"redux-mock-store": "^1.5.3",

yarn.lock

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,20 @@
690690
"@babel/plugin-transform-react-jsx-self" "^7.0.0"
691691
"@babel/plugin-transform-react-jsx-source" "^7.0.0"
692692

693-
"@babel/runtime@^7.0.0", "@babel/runtime@^7.3.1":
693+
"@babel/runtime@^7.0.0":
694694
version "7.4.3"
695695
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.3.tgz#79888e452034223ad9609187a0ad1fe0d2ad4bdc"
696696
integrity sha512-9lsJwJLxDh/T3Q3SZszfWOTkk3pHbkmH+3KY+zwIDmsNlxsumuhS2TH3NIpktU4kNvfzy+k3eLT7aTJSPTo0OA==
697697
dependencies:
698698
regenerator-runtime "^0.13.2"
699699

700+
"@babel/runtime@^7.4.3":
701+
version "7.4.5"
702+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12"
703+
integrity sha512-TuI4qpWZP6lGOGIuGWtp9sPluqYICmbk8T/1vpSysqJxRPkudh/ofFWyqdcMsDf2s7KvDL4/YHgKyvcS3g9CJQ==
704+
dependencies:
705+
regenerator-runtime "^0.13.2"
706+
700707
"@babel/template@^7.0.0", "@babel/template@^7.1.0", "@babel/template@^7.2.2", "@babel/template@^7.4.0":
701708
version "7.4.0"
702709
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.4.0.tgz#12474e9c077bae585c5d835a95c0b0b790c25c8b"
@@ -5540,22 +5547,22 @@ react-dom@^16.8.6:
55405547
prop-types "^15.6.2"
55415548
scheduler "^0.13.6"
55425549

5543-
react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.2, react-is@^16.8.4, react-is@^16.8.6:
5550+
react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6:
55445551
version "16.8.6"
55455552
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
55465553
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
55475554

5548-
react-redux@^6.0.1:
5549-
version "6.0.1"
5550-
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-6.0.1.tgz#0d423e2c1cb10ada87293d47e7de7c329623ba4d"
5551-
integrity sha512-T52I52Kxhbqy/6TEfBv85rQSDz6+Y28V/pf52vDWs1YRXG19mcFOGfHnY2HsNFHyhP+ST34Aih98fvt6tqwVcQ==
5555+
react-redux@^7.0.3:
5556+
version "7.0.3"
5557+
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.0.3.tgz#983c5a6de81cb1e696bd1c090ba826545f9170f1"
5558+
integrity sha512-vYZA7ftOYlDk3NetitsI7fLjryt/widNl1SLXYvFenIpm7vjb4ryK0EeFrgn62usg5fYkyIAWNUPKnwWPevKLg==
55525559
dependencies:
5553-
"@babel/runtime" "^7.3.1"
5560+
"@babel/runtime" "^7.4.3"
55545561
hoist-non-react-statics "^3.3.0"
55555562
invariant "^2.2.4"
55565563
loose-envify "^1.4.0"
55575564
prop-types "^15.7.2"
5558-
react-is "^16.8.2"
5565+
react-is "^16.8.6"
55595566

55605567
react-test-renderer@^16.0.0-0, react-test-renderer@^16.8.6:
55615568
version "16.8.6"

0 commit comments

Comments
 (0)