import React from 'react'; import { mount } from 'enzyme'; import { QueryState } from '../src'; import { MemoryRouter, Route } from 'react-router'; const Example = QueryState(({ state, setState }) => (
setState({ test: e.target.value })} />
)); test('should render with state from url', () => { const wrapper = mount( ); expect( wrapper .find('input') .first() .props().value ).toEqual('Awesome'); }); test('should update url state', done => { const wrapper = mount(
{ if (props.location.search === '?test=testing%20%26%20ampersand%21') done(); return null; }} />
); wrapper .find('input') .first() .simulate('change', { target: { value: 'testing & ampersand!' } }); setTimeout( () => expect( wrapper .find('input') .first() .props().value ).toEqual('testing & ampersand!'), 400 ); });