Guest User

Untitled

a guest
Nov 20th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. it('puts the lotion in the basket', () => {
  2. const wrapper = mount(
  3. <MemoryRouter>
  4. <Foo />
  5. </MemoryRouter>
  6. )
  7.  
  8. wrapper.state('name') // this returns null! We are accessing the MemoryRouter's state, which isn't what we want!
  9. wrapper.find(Foo).state('name') // this breaks! state() can only be called on the root!
  10. })
  11.  
  12. class Foo extends Component {
  13. state = {
  14. bar: 'here is the state!'
  15. }
  16.  
  17. render () {
  18. return (
  19. <Link to='/'>Here is a link</Link>
  20. )
  21. }
  22. }
  23.  
  24. it('puts the lotion in the basket', () => {
  25. const wrapper = mount(
  26. <MemoryRouter>
  27. <Foo />
  28. </MemoryRouter>
  29. )
  30.  
  31. expect(wrapper.find(Foo).instance().state).toEqual({
  32. bar: 'here is the state!'
  33. })
  34. })
  35.  
  36. it('puts the lotion in the basket shallowly', () => {
  37. const wrapper = shallow(
  38. <MemoryRouter>
  39. <Foo />
  40. </MemoryRouter>
  41. )
  42.  
  43. expect(wrapper.find(Foo).dive().instance().state).toEqual({
  44. bar: 'here is the state!'
  45. })
  46. })
Add Comment
Please, Sign In to add comment