Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- it('puts the lotion in the basket', () => {
- const wrapper = mount(
- <MemoryRouter>
- <Foo />
- </MemoryRouter>
- )
- wrapper.state('name') // this returns null! We are accessing the MemoryRouter's state, which isn't what we want!
- wrapper.find(Foo).state('name') // this breaks! state() can only be called on the root!
- })
- class Foo extends Component {
- state = {
- bar: 'here is the state!'
- }
- render () {
- return (
- <Link to='/'>Here is a link</Link>
- )
- }
- }
- it('puts the lotion in the basket', () => {
- const wrapper = mount(
- <MemoryRouter>
- <Foo />
- </MemoryRouter>
- )
- expect(wrapper.find(Foo).instance().state).toEqual({
- bar: 'here is the state!'
- })
- })
- it('puts the lotion in the basket shallowly', () => {
- const wrapper = shallow(
- <MemoryRouter>
- <Foo />
- </MemoryRouter>
- )
- expect(wrapper.find(Foo).dive().instance().state).toEqual({
- bar: 'here is the state!'
- })
- })
Add Comment
Please, Sign In to add comment