From feaae62038535abeb938539e83b9f688736506a0 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 12 Aug 2019 11:17:16 +0200 Subject: [PATCH] WithContactDetailsValidation Unit Test: pass Redux store as wrappingComponent, use full mount React Redux 7.x no longer supports `store` prop for `Provider`, and uses the new `React.createContext()` instead of the legacy context. That requires an update of the unit tests. - use `wrappingComponent` option to activate a mock Redux provider - switch to full mount, as `wrappingComponent` doesn't work with `useContext` in Enzyme (airbnb/enzyme#2176) --- .../test/with-contact-details-validation.js | 58 +++++++++++-------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/client/components/domains/registrant-extra-info/test/with-contact-details-validation.js b/client/components/domains/registrant-extra-info/test/with-contact-details-validation.js index 3b21f7dfdc853..64a5cc222193f 100644 --- a/client/components/domains/registrant-extra-info/test/with-contact-details-validation.js +++ b/client/components/domains/registrant-extra-info/test/with-contact-details-validation.js @@ -1,29 +1,36 @@ -/** @format */ +/** + * @jest-environment jsdom + */ + /** * External dependencies */ import React from 'react'; -import { shallow } from 'enzyme'; +import { Provider } from 'react-redux'; +import { mount } from 'enzyme'; import { difference, identity, set } from 'lodash'; /** * Internal dependencies */ -import { ValidatedRegistrantExtraInfoUkForm } from '../uk-form'; +import { ValidatedRegistrantExtraInfoUkForm, RegistrantExtraInfoUkForm } from '../uk-form'; jest.mock( 'state/selectors/get-validation-schemas', () => () => ( { uk: require( './uk-schema.json' ), } ) ); +const mockStore = { + getState: () => ( {} ), + subscribe: () => () => {}, + dispatch: () => {}, +}; + +const MockReduxProvider = ( { children } ) => { children }; + const mockProps = { translate: identity, updateContactDetailsCache: identity, tld: 'uk', - store: { - getState: () => {}, - subscribe: () => {}, - dispatch: () => {}, - }, }; describe( 'uk-form validation', () => { @@ -76,13 +83,14 @@ describe( 'uk-form validation', () => { }; needsRegistrationNumber.forEach( registrantType => { - const wrapper = shallow( + const wrapper = mount( - ).dive(); + />, + { wrappingComponent: MockReduxProvider } + ).find( RegistrantExtraInfoUkForm ); expect( wrapper.props() ).toMatchObject( { validationErrors: { @@ -109,13 +117,14 @@ describe( 'uk-form validation', () => { }; difference( allRegistrantTypes, needsRegistrationNumber ).forEach( registrantType => { - const wrapper = shallow( + const wrapper = mount( - ).dive(); + />, + { wrappingComponent: MockReduxProvider } + ).find( RegistrantExtraInfoUkForm ); expect( wrapper.props() ).toHaveProperty( 'validationErrors', {} ); } ); @@ -134,7 +143,7 @@ describe( 'uk-form validation', () => { const badFormats = [ '124', 'OC38599', '066566879', 'OCABCDEF', '054025OC' ]; badFormats.forEach( registrationNumber => { - const wrapper = shallow( + const wrapper = mount( { registrationNumber ) } ccTldDetails={ { registrationNumber } } - /> - ).dive(); + />, + { wrappingComponent: MockReduxProvider } + ).find( RegistrantExtraInfoUkForm ); expect( wrapper.props() ).toHaveProperty( 'validationErrors.extra.uk.registrationNumber' ); } ); @@ -164,13 +174,14 @@ describe( 'uk-form validation', () => { }; needsTradingName.forEach( registrantType => { - const wrapper = shallow( + const wrapper = mount( - ).dive(); + />, + { wrappingComponent: MockReduxProvider } + ).find( RegistrantExtraInfoUkForm ); expect( wrapper.props() ).toMatchObject( { validationErrors: { @@ -198,13 +209,14 @@ describe( 'uk-form validation', () => { }, }; - const wrapper = shallow( + const wrapper = mount( - ).dive(); + />, + { wrappingComponent: MockReduxProvider } + ).find( RegistrantExtraInfoUkForm ); expect( wrapper.props() ).toHaveProperty( 'validationErrors', {} ); } );