From 4f73b5a7f3d6f7177f03fd31c6a51f1ce018aef0 Mon Sep 17 00:00:00 2001 From: Tom <20648924+moT01@users.noreply.github.com> Date: Wed, 8 May 2019 09:17:54 -0500 Subject: [PATCH] Fix/manage state locally tests (#35980) * fix/manage-state-locally-test * fix/update-test-words * fix/update-test --- .../react-and-redux/manage-state-locally-first.english.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/curriculum/challenges/english/03-front-end-libraries/react-and-redux/manage-state-locally-first.english.md b/curriculum/challenges/english/03-front-end-libraries/react-and-redux/manage-state-locally-first.english.md index cd1bf2aad74..f9a69460859 100644 --- a/curriculum/challenges/english/03-front-end-libraries/react-and-redux/manage-state-locally-first.english.md +++ b/curriculum/challenges/english/03-front-end-libraries/react-and-redux/manage-state-locally-first.english.md @@ -25,7 +25,9 @@ tests: - text: 'The DisplayMessages component should initialize with a state equal to { input: "", messages: [] }.' testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const initialState = mockedComponent.state(); return ( typeof initialState === ''object'' && initialState.input === '''' && initialState.messages.length === 0); })(), ''The DisplayMessages component should initialize with a state equal to { input: "", messages: [] }.'');' - text: The DisplayMessages component should render a div containing an h2 element, a button element, a ul element, and li elements as children. - testString: 'async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const state = () => { mockedComponent.setState({messages: [''__TEST__MESSAGE'']}); return waitForIt(() => mockedComponent )}; const updated = await state(); assert(updated.find(''div'').length === 1 && updated.find(''h2'').length === 1 && updated.find(''button'').length === 1 && updated.find(''ul'').length === 1, ''The DisplayMessages component should render a div containing an h2 element, a button element, a ul element, and li elements as children.''); }; ' + testString: 'async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const state = () => { mockedComponent.setState({messages: [''__TEST__MESSAGE'']}); return waitForIt(() => mockedComponent )}; const updated = await state(); assert(updated.find(''div'').length === 1 && updated.find(''h2'').length === 1 && updated.find(''button'').length === 1 && updated.find(''ul'').length === 1 && updated.find(''li'').length > 0, ''The DisplayMessages component should render a div containing an h2 element, a button element, a ul element, and li elements as children.''); }; ' + - text: .map was used on the messages array. + testString: assert(code.match(/this\.state\.messages\.map/g)); - text: The input element should render the value of input in local state. testString: 'async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const causeChange = (c, v) => c.find(''input'').simulate(''change'', { target: { value: v }}); const testValue = ''__TEST__EVENT__INPUT''; const changed = () => { causeChange(mockedComponent, testValue); return waitForIt(() => mockedComponent )}; const updated = await changed(); assert(updated.find(''input'').props().value === testValue, ''The input element should render the value of input in local state.''); }; ' - text: Calling the method handleChange should update the input value in state to the current input.