Files
freeCodeCamp/client/src/components/Header/Header.test.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

/* global expect */
import React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow';
import TestRenderer from 'react-test-renderer';
import { UniversalNav } from './components/UniversalNav';
import NavLinks from './components/NavLinks';
describe('<UniversalNav />', () => {
it('renders to the DOM', () => {
const shallow = new ShallowRenderer();
shallow.render(<UniversalNav {...UniversalNavProps} />);
const result = shallow.getRenderOutput();
expect(result).toBeTruthy();
});
});
describe('<NavLinks />', () => {
const root = TestRenderer.create(<NavLinks />).root;
const aTags = root.findAllByType('a');
// reduces the aTags to href links
const links = aTags.reduce((acc, item) => {
acc.push(item._fiber.pendingProps.href);
return acc;
}, []);
const expectedLinks = ['/learn', '/portfolio', '/news', '/forum'];
it('renders to the DOM', () => {
expect(root).toBeTruthy();
});
2019-10-04 19:31:29 +03:00
it('has 2 links', () => {
expect(aTags.length === 4).toBeTruthy();
});
it('has links to news, forum, learn and portfolio', () => {
// checks if all links in expected links exist in links
expect(expectedLinks.every(elem => links.indexOf(elem) > -1)).toBeTruthy();
});
});
const UniversalNavProps = {
displayMenu: false,
menuButtonRef: {},
searchBarRef: {},
toggleDisplayMenu: function() {}
};