Skip to content

Commit

Permalink
Testing: Enforce path argument as array universally
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 1, 2018
1 parent f0ec595 commit c3b2e6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ module.exports = {
message: 'Deprecated functions must be removed before releasing this version.',
},
{
selector: 'CallExpression[callee.name="get"] > Literal:nth-child(2)',
message: 'Always pass an array as the second argument of Lodash.get',
selector: 'CallExpression[callee.name=/^(invokeMap|get|has|hasIn|invoke|result|set|setWith|unset|update|updateWith)$/] > Literal:nth-child(2)',
message: 'Always pass an array as the path argument',
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion components/code-editor/test/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CodeEditor from '../editor';

describe( 'CodeEditor', () => {
it( 'should render without an error', () => {
set( global, 'wp.codeEditor.initialize', () => ( {
set( global, [ 'wp', 'codeEditor', 'initialize' ], () => ( {
codemirror: {
on: noop,
hasFocus: () => false,
Expand Down
28 changes: 14 additions & 14 deletions editor/store/test/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ describe( 'effects', () => {
},
] );

set( global, 'wp.api.getPostTypeRoute', () => 'blocks' );
set( global, 'wp.apiRequest', () => promise );
set( global, [ 'wp', 'api', 'getPostTypeRoute' ], () => 'blocks' );
set( global, [ 'wp', 'apiRequest' ], () => promise );

const dispatch = jest.fn();
const store = { getState: noop, dispatch };
Expand Down Expand Up @@ -645,8 +645,8 @@ describe( 'effects', () => {
content: '<!-- wp:test-block {"name":"Big Bird"} /-->',
} );

set( global, 'wp.api.getPostTypeRoute', () => 'blocks' );
set( global, 'wp.apiRequest', () => promise );
set( global, [ 'wp', 'api', 'getPostTypeRoute' ], () => 'blocks' );
set( global, [ 'wp', 'apiRequest' ], () => promise );

const dispatch = jest.fn();
const store = { getState: noop, dispatch };
Expand Down Expand Up @@ -679,8 +679,8 @@ describe( 'effects', () => {
it( 'should handle an API error', () => {
const promise = Promise.reject( {} );

set( global, 'wp.api.getPostTypeRoute', () => 'blocks' );
set( global, 'wp.apiRequest', () => promise );
set( global, [ 'wp', 'api', 'getPostTypeRoute' ], () => 'blocks' );
set( global, [ 'wp', 'apiRequest' ], () => promise );

const dispatch = jest.fn();
const store = { getState: noop, dispatch };
Expand Down Expand Up @@ -722,8 +722,8 @@ describe( 'effects', () => {
let modelAttributes;
const promise = Promise.resolve( { id: 456 } );

set( global, 'wp.api.getPostTypeRoute', () => 'blocks' );
set( global, 'wp.apiRequest', ( request ) => {
set( global, [ 'wp', 'api', 'getPostTypeRoute' ], () => 'blocks' );
set( global, [ 'wp', 'apiRequest' ], ( request ) => {
modelAttributes = request.data;
return promise;
} );
Expand Down Expand Up @@ -759,8 +759,8 @@ describe( 'effects', () => {
it( 'should handle an API error', () => {
const promise = Promise.reject( {} );

set( global, 'wp.api.getPostTypeRoute', () => 'blocks' );
set( global, 'wp.apiRequest', () => promise );
set( global, [ 'wp', 'api', 'getPostTypeRoute' ], () => 'blocks' );
set( global, [ 'wp', 'apiRequest' ], () => promise );

const sharedBlock = { id: 123, title: 'My cool block' };
const parsedBlock = createBlock( 'core/test-block', { name: 'Big Bird' } );
Expand Down Expand Up @@ -790,8 +790,8 @@ describe( 'effects', () => {
it( 'should delete a shared block', () => {
const promise = Promise.resolve( {} );

set( global, 'wp.api.getPostTypeRoute', () => 'blocks' );
set( global, 'wp.apiRequest', () => promise );
set( global, [ 'wp', 'api', 'getPostTypeRoute' ], () => 'blocks' );
set( global, [ 'wp', 'apiRequest' ], () => promise );

const associatedBlock = createBlock( 'core/block', { ref: 123 } );
const sharedBlock = { id: 123, title: 'My cool block' };
Expand Down Expand Up @@ -830,8 +830,8 @@ describe( 'effects', () => {
it( 'should handle an API error', () => {
const promise = Promise.reject( {} );

set( global, 'wp.api.getPostTypeRoute', () => 'blocks' );
set( global, 'wp.apiRequest', () => promise );
set( global, [ 'wp', 'api', 'getPostTypeRoute' ], () => 'blocks' );
set( global, [ 'wp', 'apiRequest' ], () => promise );

const sharedBlock = { id: 123, title: 'My cool block' };
const parsedBlock = createBlock( 'core/test-block', { name: 'Big Bird' } );
Expand Down

0 comments on commit c3b2e6c

Please sign in to comment.