From e2a414c52abe956310f37e9028427af57bd6edad Mon Sep 17 00:00:00 2001 From: Rodrigo Iloro Date: Sat, 8 Sep 2018 00:11:23 -0300 Subject: [PATCH] Migrating tests to jest --- .../state/data-layer/wp/sites/posts/index.js | 4 --- .../data-layer/wp/sites/posts/test/index.js | 30 ++++++++----------- client/state/gutenberg/test/reducer.js | 5 ++-- .../test/get-gutenberg-current-post.js | 9 ++---- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/client/state/data-layer/wp/sites/posts/index.js b/client/state/data-layer/wp/sites/posts/index.js index 58041056b2a555..b53aea1b14cb52 100644 --- a/client/state/data-layer/wp/sites/posts/index.js +++ b/client/state/data-layer/wp/sites/posts/index.js @@ -1,9 +1,5 @@ /** @format */ -/** - * External dependencies - */ - /** * Internal dependencies */ diff --git a/client/state/data-layer/wp/sites/posts/test/index.js b/client/state/data-layer/wp/sites/posts/test/index.js index 6f10a33918a716..5cf47640cd6026 100644 --- a/client/state/data-layer/wp/sites/posts/test/index.js +++ b/client/state/data-layer/wp/sites/posts/test/index.js @@ -1,11 +1,5 @@ /** @format */ -/** - * External dependencies - */ -import { expect } from 'chai'; -import { spy } from 'sinon'; - /** * Internal dependencies */ @@ -29,13 +23,13 @@ describe( 'wp-api', () => { describe( 'Gutenberg site posts', () => { describe( 'requestGutenbergPostDraft()', () => { test( "should dispatch a HTTP request to Gutenberg's create draft endpoint", () => { - const dispatch = spy(); + const dispatch = jest.fn(); const action = { type: GUTENBERG_SITE_CREATE_DRAFT, siteId: SITE_ID }; requestGutenbergPostDraft( { dispatch }, action ); - expect( dispatch ).to.have.been.calledOnce; - expect( dispatch ).to.have.been.calledWith( + expect( dispatch ).toHaveBeenCalledTimes( 1 ); + expect( dispatch ).toHaveBeenCalledWith( http( { path: `/sites/${ SITE_ID }/posts/create-draft`, @@ -50,12 +44,12 @@ describe( 'wp-api', () => { describe( 'createSitePostSuccess()', () => { test( 'should dispatch an action to request the created post for Gutenberg', () => { - const dispatch = spy(); + const dispatch = jest.fn(); createSitePostSuccess( { dispatch }, { siteId: SITE_ID }, { ID: POST_ID } ); - expect( dispatch ).to.have.been.calledOnce; - expect( dispatch ).to.have.been.calledWith( { + expect( dispatch ).toHaveBeenCalledTimes( 1 ); + expect( dispatch ).toHaveBeenCalledWith( { type: GUTENBERG_SITE_POST_REQUEST, siteId: SITE_ID, postId: POST_ID, @@ -65,12 +59,12 @@ describe( 'wp-api', () => { describe( 'fetchSitePost()', () => { test( 'should dispatch a HTTP request to fetch a post for Gutenberg', () => { - const dispatch = spy(); + const dispatch = jest.fn(); const action = { type: GUTENBERG_SITE_POST_REQUEST, siteId: SITE_ID, postId: POST_ID }; fetchSitePost( { dispatch }, action ); - expect( dispatch ).to.have.been.calledOnce; - expect( dispatch ).to.have.been.calledOnceWith( + expect( dispatch ).toHaveBeenCalledTimes( 1 ); + expect( dispatch ).toHaveBeenCalledWith( http( { path: `/sites/${ SITE_ID }/posts/${ POST_ID }?context=edit`, @@ -85,12 +79,12 @@ describe( 'wp-api', () => { describe( 'fetchSitePostSuccess()', () => { test( "should dispatch an action to update Gutenberg's current post", () => { - const dispatch = spy(); + const dispatch = jest.fn(); fetchSitePostSuccess( { dispatch }, { siteId: SITE_ID, postId: POST_ID }, { id: POST_ID } ); - expect( dispatch ).to.have.been.calledOnce; - expect( dispatch ).to.have.been.calledWith( { + expect( dispatch ).toHaveBeenCalledTimes( 1 ); + expect( dispatch ).toHaveBeenCalledWith( { type: GUTENBERG_SITE_POST_RECEIVE, siteId: SITE_ID, postId: POST_ID, diff --git a/client/state/gutenberg/test/reducer.js b/client/state/gutenberg/test/reducer.js index 0355ba3d6ab5e7..bad1b2f7d287b8 100644 --- a/client/state/gutenberg/test/reducer.js +++ b/client/state/gutenberg/test/reducer.js @@ -2,7 +2,6 @@ /** * External dependencies */ -import { expect } from 'chai'; import deepFreeze from 'deep-freeze'; /** @@ -16,7 +15,7 @@ describe( 'reducer', () => { test( 'should default to an empty object', () => { const state = currentPost( undefined, {} ); - expect( state ).to.eql( { currentPost: {} } ); + expect( state ).toMatchObject( { currentPost: {} } ); } ); test( 'should replace the Gutenberg current post', () => { @@ -26,7 +25,7 @@ describe( 'reducer', () => { post: { id: 2 }, } ); - expect( newSate ).to.eql( { currentPost: { id: 2 } } ); + expect( newSate ).toMatchObject( { currentPost: { id: 2 } } ); } ); } ); } ); diff --git a/client/state/selectors/test/get-gutenberg-current-post.js b/client/state/selectors/test/get-gutenberg-current-post.js index f847e21c8ee9a2..6d87a6c4c6384c 100644 --- a/client/state/selectors/test/get-gutenberg-current-post.js +++ b/client/state/selectors/test/get-gutenberg-current-post.js @@ -1,10 +1,5 @@ /** @format */ -/** - * External dependencies - */ -import { expect } from 'chai'; - /** * Internal dependencies */ @@ -14,13 +9,13 @@ describe( 'getGutenbergCurrentPost()', () => { test( 'should return null if there are no current post for Gutenberg', () => { const currentPost = getGutenbergCurrentPost( {} ); - expect( currentPost ).to.be.null; + expect( currentPost ).toBeNull(); } ); test( 'should return the current loaded post for Gutenberg', () => { const state = { gutenberg: { currentPost: { id: 1 } } }; const currentPost = getGutenbergCurrentPost( state ); - expect( currentPost ).to.eql( currentPost ); + expect( currentPost ).toMatchObject( { id: 1 } ); } ); } );