From 295169d564ebd8314eb7b34913e0da16ec6ef42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A2=D0=BA?= =?UTF-8?q?=D0=B0=D1=87=D1=83=D0=BA?= Date: Tue, 4 Jun 2019 17:13:54 +0300 Subject: [PATCH] WIP Pending bug tests --- __tests__/wrappers/withAsyncActions.spec.js | 19 ++++++- __tests__/wrappers/withAsyncHandlers.spec.js | 54 ++++++++++++++++++-- package.json | 2 +- yarn.lock | 23 ++++++--- 4 files changed, 83 insertions(+), 15 deletions(-) diff --git a/__tests__/wrappers/withAsyncActions.spec.js b/__tests__/wrappers/withAsyncActions.spec.js index 83a27d0..6f185aa 100644 --- a/__tests__/wrappers/withAsyncActions.spec.js +++ b/__tests__/wrappers/withAsyncActions.spec.js @@ -419,7 +419,7 @@ describe('With Async Client HOC', () => { const ComponentWithMetaHandler = withAsyncActions({ firstAction: firstAction.withSuccessHandler(({ action }) => action()), secondAction: secondAction.withErrorHandler(({ action }) => action()), - thirdAction: thirdAction.withPendingHandler(({ action }) => action()) + thirdAction: thirdAction.withPendingHandler((props, action) => props.action(props, action)) })(Component); const { wrapper } = setupComponent(ComponentWithMetaHandler); @@ -452,6 +452,23 @@ describe('With Async Client HOC', () => { component.props().thirdAction.dispatch(defer.promise); defer.resolve(); + expect(component.props().action).lastCalledWith( + expect.objectContaining({ + thirdAction: expect.objectContaining({ + meta: expect.objectContaining({ + pending: true, + success: false, + error: false, + }), + }) + }), + expect.objectContaining({ + requestAction: expect.objectContaining({ + payload: expect.anything(), + }) + }) + ); + await defer.promise.then(); expect(component.props().action).toHaveBeenCalledTimes(3); diff --git a/__tests__/wrappers/withAsyncHandlers.spec.js b/__tests__/wrappers/withAsyncHandlers.spec.js index 3a6e3df..26d7d42 100644 --- a/__tests__/wrappers/withAsyncHandlers.spec.js +++ b/__tests__/wrappers/withAsyncHandlers.spec.js @@ -70,6 +70,38 @@ describe('Async Client withHandlers HOC', () => { await defer.promise.then(); expect(successHandler).toHaveBeenCalledTimes(1); + expect(successHandler).lastCalledWith( + expect.objectContaining({ + action: expect.objectContaining({ + meta: expect.objectContaining({ + pending: false, + success: true, + error: false, + }), + }) + }), + expect.objectContaining({ + requestAction: expect.objectContaining({ + payload: expect.anything(), + }) + }) + ); + }); + + it('should handle withPendingHandler()', async () => { + expect(pendingHandler).toHaveBeenCalledTimes(1); + expect(pendingHandler).lastCalledWith( + expect.objectContaining({ + action: expect.objectContaining({ + meta: expect.objectContaining({ + pending: true, + success: false, + error: false, + }), + }) + }), + expect.anything() + ); }); it('should handle withErrorHandler()', async () => { @@ -81,13 +113,25 @@ describe('Async Client withHandlers HOC', () => { await defer.promise.catch(); } catch(e) { expect(errorHandler).toHaveBeenCalledTimes(1); + expect(errorHandler).lastCalledWith( + expect.objectContaining({ + action: expect.objectContaining({ + meta: expect.objectContaining({ + pending: false, + success: false, + error: expect.anything(), + }), + }) + }), + expect.objectContaining({ + requestAction: expect.objectContaining({ + payload: expect.anything(), + }) + }) + ); } }); - it('should handle withPendingHandler()', async () => { - expect(pendingHandler).toHaveBeenCalledTimes(2); - }); - it('should pass action to handler', async () => { component.props().action.dispatch('action_payload'); expect(pendingHandler).lastCalledWith( @@ -98,7 +142,7 @@ describe('Async Client withHandlers HOC', () => { }) }) ); - }) + }); }); describe('withAsyncHandlers({ metaHandler })', () => { diff --git a/package.json b/package.json index 076ecb2..ed607da 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "ramda": "^0.26.1", "react": "^16.8.6", "react-dom": "^16.8.6", - "react-redux": "^6.0.1", + "react-redux": "^7.0.3", "react-test-renderer": "^16.8.6", "redux": "^4.0.1", "redux-mock-store": "^1.5.3", diff --git a/yarn.lock b/yarn.lock index 716e546..38f3a3f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -690,13 +690,20 @@ "@babel/plugin-transform-react-jsx-self" "^7.0.0" "@babel/plugin-transform-react-jsx-source" "^7.0.0" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.3.1": +"@babel/runtime@^7.0.0": version "7.4.3" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.3.tgz#79888e452034223ad9609187a0ad1fe0d2ad4bdc" integrity sha512-9lsJwJLxDh/T3Q3SZszfWOTkk3pHbkmH+3KY+zwIDmsNlxsumuhS2TH3NIpktU4kNvfzy+k3eLT7aTJSPTo0OA== dependencies: regenerator-runtime "^0.13.2" +"@babel/runtime@^7.4.3": + version "7.4.5" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12" + integrity sha512-TuI4qpWZP6lGOGIuGWtp9sPluqYICmbk8T/1vpSysqJxRPkudh/ofFWyqdcMsDf2s7KvDL4/YHgKyvcS3g9CJQ== + dependencies: + regenerator-runtime "^0.13.2" + "@babel/template@^7.0.0", "@babel/template@^7.1.0", "@babel/template@^7.2.2", "@babel/template@^7.4.0": version "7.4.0" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.4.0.tgz#12474e9c077bae585c5d835a95c0b0b790c25c8b" @@ -5540,22 +5547,22 @@ react-dom@^16.8.6: prop-types "^15.6.2" scheduler "^0.13.6" -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: +react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6: version "16.8.6" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA== -react-redux@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-6.0.1.tgz#0d423e2c1cb10ada87293d47e7de7c329623ba4d" - integrity sha512-T52I52Kxhbqy/6TEfBv85rQSDz6+Y28V/pf52vDWs1YRXG19mcFOGfHnY2HsNFHyhP+ST34Aih98fvt6tqwVcQ== +react-redux@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.0.3.tgz#983c5a6de81cb1e696bd1c090ba826545f9170f1" + integrity sha512-vYZA7ftOYlDk3NetitsI7fLjryt/widNl1SLXYvFenIpm7vjb4ryK0EeFrgn62usg5fYkyIAWNUPKnwWPevKLg== dependencies: - "@babel/runtime" "^7.3.1" + "@babel/runtime" "^7.4.3" hoist-non-react-statics "^3.3.0" invariant "^2.2.4" loose-envify "^1.4.0" prop-types "^15.7.2" - react-is "^16.8.2" + react-is "^16.8.6" react-test-renderer@^16.0.0-0, react-test-renderer@^16.8.6: version "16.8.6"