Guest User

Untitled

a guest
Oct 19th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import Enzyme from 'enzyme';
  2. import Adapter from 'enzyme-adapter-react-15';
  3. import React from 'react';
  4. import { expect } from 'chai';
  5. import { shallow, mount, render } from 'enzyme';
  6.  
  7. import ToDo from './ToDo';
  8.  
  9. Enzyme.configure({ adapter: new Adapter() });
  10.  
  11.  
  12. describe(<ToDo/>, () => {
  13. it('updates state when todo is added', () => {
  14. global.localStorage = {
  15. getItem: () => {},
  16. setItem: () => {}
  17. };
  18.  
  19. const wrapper = mount(<ToDo />);
  20. wrapper.instance().newToDo('title', 'text');
  21.  
  22. expect(wrapper.state().todos).to.have.length(1);
  23. });
  24.  
  25. it('updates localstorage when todo is added', () => {
  26. global.localStorageData = {};
  27. global.localStorage = {
  28. getItem: () => {},
  29. setItem: (key, value) => {
  30. localStorageData[key] = value;
  31. }
  32. };
  33.  
  34. const wrapper = mount(<ToDo />);
  35. wrapper.instance().newToDo('title', 'text');
  36.  
  37. expect(JSON.parse(localStorageData.todos)).to.have.length(1);
  38. });
  39.  
  40. it('updates state when todo is deleted', () => {
  41. global.localStorage = {
  42. getItem: () => {},
  43. setItem: (a, b) => {}
  44. };
  45.  
  46. const wrapper = mount(<ToDo />);
  47. wrapper.instance().newToDo('title', 'text');
  48. wrapper.instance().newToDo('title', 'text');
  49.  
  50. expect(wrapper.state().todos).to.have.length(2);
  51.  
  52. wrapper.instance().removeToDo(0);
  53.  
  54. expect(wrapper.state().todos).to.have.length(1);
  55. });
  56.  
  57. it('renders todo items', () => {
  58. global.localStorage = {
  59. getItem: () => {},
  60. setItem: (a, b) => {}
  61. };
  62.  
  63. const wrapper = mount(<ToDo />);
  64.  
  65. wrapper.instance().newToDo('title', 'text');
  66. wrapper.instance().newToDo('title', 'text');
  67.  
  68. expect(wrapper.render().find('.todos').siblings().length).to.equal(2);
  69. });
  70. });
Add Comment
Please, Sign In to add comment