diff --git a/components/notice/test/__snapshots__/index.js.snap b/components/notice/test/__snapshots__/index.js.snap
new file mode 100644
index 0000000000000..e966f19b11ef2
--- /dev/null
+++ b/components/notice/test/__snapshots__/index.js.snap
@@ -0,0 +1,19 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Notice should match snapshot 1`] = `
+
+
+
+`;
diff --git a/components/notice/test/index.js b/components/notice/test/index.js
index 0893f108db285..0b6223b8a7e74 100644
--- a/components/notice/test/index.js
+++ b/components/notice/test/index.js
@@ -9,13 +9,12 @@ import { shallow } from 'enzyme';
import Notice from '../index';
describe( 'Notice', () => {
- it( 'should have valid class names', () => {
+ it( 'should match snapshot', () => {
const wrapper = shallow( );
- expect( wrapper.hasClass( 'notice' ) ).toBe( true );
- expect( wrapper.hasClass( 'notice-alt' ) ).toBe( true );
- expect( wrapper.hasClass( 'notice-example' ) ).toBe( true );
- expect( wrapper.hasClass( 'is-dismissible' ) ).toBe( true );
+
+ expect( wrapper ).toMatchSnapshot();
} );
+
it( 'should not have is-dismissible class when isDismissible prop is false', () => {
const wrapper = shallow( );
expect( wrapper.hasClass( 'is-dismissible' ) ).toBe( false );
diff --git a/package-lock.json b/package-lock.json
index 2c6cffe389fa5..5db8d08a511ce 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2821,9 +2821,9 @@
}
},
"enzyme-to-json": {
- "version": "3.1.4",
- "resolved": "https://registry.npmjs.org/enzyme-to-json/-/enzyme-to-json-3.1.4.tgz",
- "integrity": "sha512-bGXQxsbVdRqn3ebWej90ADH+RmlKXwy4SgMWc1gG4oDKlVHEsu2eP6hMA4zFGMlQqTxgyd1XPcsryo6Ti4YG+Q==",
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/enzyme-to-json/-/enzyme-to-json-3.2.2.tgz",
+ "integrity": "sha512-Paym79t9PFsTxvazN5+k9aZfoZO+lul/qDLspL1UlNwhbg+RUczVuuP4SO/RZ/sFRxal3dPCl+5VmqtCE1bxBw==",
"dev": true,
"requires": {
"lodash": "4.17.4"
@@ -5893,7 +5893,7 @@
"dev": true,
"requires": {
"enzyme-matchers": "4.0.1",
- "enzyme-to-json": "3.1.4"
+ "enzyme-to-json": "3.2.2"
}
},
"jest-get-type": {
diff --git a/test/unit/setup-test-framework.js b/test/unit/setup-test-framework.js
index 37b6bbf123fd4..97e66972157b1 100644
--- a/test/unit/setup-test-framework.js
+++ b/test/unit/setup-test-framework.js
@@ -1,14 +1,26 @@
// `babel-jest` should be doing this instead, but apparently it's not working.
require( 'core-js/modules/es7.object.values' );
-/**
- * External dependencies
- */
-import Adapter from 'enzyme-adapter-react-16';
-import Enzyme from 'enzyme';
-import 'jest-enzyme';
+// 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;
-Enzyme.configure( { adapter: new Adapter() } );
+jest.mock( 'enzyme', () => {
+ const actualEnzyme = require.requireActual( 'enzyme' );
+ if ( ! mockEnzymeSetup ) {
+ mockEnzymeSetup = true;
+
+ // configure enzyme 3 for React, from docs: http://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;
+} );
// Sets spies on console object to make it possible to convert them into test failures.
const spyError = jest.spyOn( console, 'error' );