Skip to content

Commit

Permalink
Migrating tests to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Iloro committed Sep 8, 2018
1 parent 9795039 commit e2a414c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
4 changes: 0 additions & 4 deletions client/state/data-layer/wp/sites/posts/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/** @format */

/**
* External dependencies
*/

/**
* Internal dependencies
*/
Expand Down
30 changes: 12 additions & 18 deletions client/state/data-layer/wp/sites/posts/test/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/** @format */

/**
* External dependencies
*/
import { expect } from 'chai';
import { spy } from 'sinon';

/**
* Internal dependencies
*/
Expand All @@ -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`,
Expand All @@ -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,
Expand All @@ -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`,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions client/state/gutenberg/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* External dependencies
*/
import { expect } from 'chai';
import deepFreeze from 'deep-freeze';

/**
Expand All @@ -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', () => {
Expand All @@ -26,7 +25,7 @@ describe( 'reducer', () => {
post: { id: 2 },
} );

expect( newSate ).to.eql( { currentPost: { id: 2 } } );
expect( newSate ).toMatchObject( { currentPost: { id: 2 } } );
} );
} );
} );
9 changes: 2 additions & 7 deletions client/state/selectors/test/get-gutenberg-current-post.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/** @format */

/**
* External dependencies
*/
import { expect } from 'chai';

/**
* Internal dependencies
*/
Expand All @@ -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 } );
} );
} );

0 comments on commit e2a414c

Please sign in to comment.