Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Enzyme from 'enzyme';
- import Adapter from 'enzyme-adapter-react-15';
- import React from 'react';
- import { expect } from 'chai';
- import { shallow, mount, render } from 'enzyme';
- import ToDo from './ToDo';
- Enzyme.configure({ adapter: new Adapter() });
- describe(<ToDo/>, () => {
- it('updates state when todo is added', () => {
- global.localStorage = {
- getItem: () => {},
- setItem: () => {}
- };
- const wrapper = mount(<ToDo />);
- wrapper.instance().newToDo('title', 'text');
- expect(wrapper.state().todos).to.have.length(1);
- });
- it('updates localstorage when todo is added', () => {
- global.localStorageData = {};
- global.localStorage = {
- getItem: () => {},
- setItem: (key, value) => {
- localStorageData[key] = value;
- }
- };
- const wrapper = mount(<ToDo />);
- wrapper.instance().newToDo('title', 'text');
- expect(JSON.parse(localStorageData.todos)).to.have.length(1);
- });
- it('updates state when todo is deleted', () => {
- global.localStorage = {
- getItem: () => {},
- setItem: (a, b) => {}
- };
- const wrapper = mount(<ToDo />);
- wrapper.instance().newToDo('title', 'text');
- wrapper.instance().newToDo('title', 'text');
- expect(wrapper.state().todos).to.have.length(2);
- wrapper.instance().removeToDo(0);
- expect(wrapper.state().todos).to.have.length(1);
- });
- it('renders todo items', () => {
- global.localStorage = {
- getItem: () => {},
- setItem: (a, b) => {}
- };
- const wrapper = mount(<ToDo />);
- wrapper.instance().newToDo('title', 'text');
- wrapper.instance().newToDo('title', 'text');
- expect(wrapper.render().find('.todos').siblings().length).to.equal(2);
- });
- });
Add Comment
Please, Sign In to add comment