-
Notifications
You must be signed in to change notification settings - Fork 4k
/
setup-test-framework.js
22 lines (18 loc) · 835 Bytes
/
setup-test-framework.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require( '@wordpress/jest-console' );
// It "mocks" enzyme, so that we can delay loading of
// the utility functions until enzyme is imported in tests.
// Props to @gdborton for sharing this technique in his article:
// https://medium.com/airbnb-engineering/unlocking-test-performance-migrating-from-mocha-to-jest-2796c508ec50.
let mockEnzymeSetup = false;
jest.mock( 'enzyme', () => {
const actualEnzyme = require.requireActual( 'enzyme' );
if ( ! mockEnzymeSetup ) {
mockEnzymeSetup = true;
// configure enzyme 3 for React, from docs: http:https://airbnb.io/enzyme/docs/installation/index.html
const Adapter = require.requireActual( 'enzyme-adapter-react-16' );
actualEnzyme.configure( { adapter: new Adapter() } );
// configure assertions for enzyme
require.requireActual( 'jest-enzyme' );
}
return actualEnzyme;
} );