From c3b2e6cc461aca3329a343bca19a6cc709da1faa Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 18 Apr 2018 10:59:33 -0400 Subject: [PATCH] Testing: Enforce path argument as array universally --- .eslintrc.js | 4 ++-- components/code-editor/test/editor.js | 2 +- editor/store/test/effects.js | 28 +++++++++++++-------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 1e7e1429e20036..ba7dcfb6eb87a6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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', }, ], }, diff --git a/components/code-editor/test/editor.js b/components/code-editor/test/editor.js index 8579eb42b2f4fd..623fff8da0b51f 100644 --- a/components/code-editor/test/editor.js +++ b/components/code-editor/test/editor.js @@ -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, diff --git a/editor/store/test/effects.js b/editor/store/test/effects.js index 4aa18d9a531143..ce515768a6c31a 100644 --- a/editor/store/test/effects.js +++ b/editor/store/test/effects.js @@ -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 }; @@ -645,8 +645,8 @@ describe( 'effects', () => { content: '', } ); - 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 }; @@ -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 }; @@ -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; } ); @@ -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' } ); @@ -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' }; @@ -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' } );