Skip to content

Commit 9d7c3e2

Browse files
committed
test: Avoid test failures from unlocking undefined stores
With the previous mock, the entire `@wordpress/data` module was replaced. This led to emptying utilities like `createReduxStore`. This resulted in other `@wordpress` modules throwing errors when attempting to act upon stores. ``` FAIL src/utils/editor.test.jsx [ src/utils/editor.test.jsx ] Error: Cannot unlock an undefined object. ❯ unlock node_modules/@wordpress/private-apis/src/implementation.ts:186:9 ❯ node_modules/@wordpress/blocks/src/store/index.js:31:1 ❯ node_modules/@wordpress/blocks/src/index.js:11:1 ```
1 parent 191d555 commit 9d7c3e2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/utils/editor.test.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import { unregisterDisallowedBlocks } from './blocks';
1616
vi.mock( '@wordpress/editor', () => ( {
1717
store: { name: 'core/editor' },
1818
} ) );
19-
vi.mock( '@wordpress/data' );
19+
vi.mock( import( '@wordpress/data' ), async ( importOriginal ) => {
20+
const actual = await importOriginal();
21+
return {
22+
...actual,
23+
dispatch: vi.fn(),
24+
};
25+
} );
2026
vi.mock( '@wordpress/preferences' );
2127
vi.mock( '@wordpress/block-library' );
2228
vi.mock( './blocks' );

0 commit comments

Comments
 (0)