yoda-common-boilerplate
Version:
Repository of all JCP reusable atoms, molecules and organisms
50 lines (39 loc) • 1.53 kB
JavaScript
import React from 'react';
import { mount, shallow } from 'enzyme';
import { expect } from 'chai';
import sinon from'sinon';
import 'ignore-styles';
import Navigation from '../Navigation.jsx';
describe('<Navigation />', () => {
let wrapper;
beforeEach(() => {
/* Shallow Rendering component in before each to eliminate duplication */
wrapper = shallow(<Navigation />);
});
it('Card component should exist ', () => {
expect(wrapper).to.exist;
});
it('component should contain a div tag as a parent', () => {
expect(wrapper.type()).to.equal('div');
});
it('component should contain a nav tag with <a> and <ul> <li>', () => {
expect(wrapper.find('nav').childAt(0).type()).to.equal('div');
expect(wrapper.find('nav').childAt(0).childAt(0).type()).to.equal('a');
expect(wrapper.find('nav').childAt(0).childAt(1).type()).to.equal('ul');
});
it('should have an initial state for isOpen ', () => {
expect(wrapper.state().isOpen).to.equal(false);
});
it('should change state for isOpen on click', () => {
const toggleMenu = sinon.spy();
wrapper.find('#menuLink').simulate('click');
expect(toggleMenu(0)).to.have.been.called;
expect(wrapper.state('isOpen')).to.equal(true);
});
it('should change state for isOpen on click of navigationToggle', () => {
const toggleMenu = sinon.spy();
wrapper.find('nav div > a').simulate('click');
expect(toggleMenu(1)).to.have.been.called;
expect(wrapper.state('isOpen')).to.equal(false);
});
});