import React from 'react'; import { mount } from 'enzyme'; import { MemoryRouter } from 'react-router-dom'; import Breadcrumbs from '../../src/components/Breadcrumbs/Breadcrumbs'; describe('', () => { let breadcrumbWrapper; let breadcrumb; let breadcrumbItem; let breadcrumbHeading; const config = { '/foo': 'Foo', '/foo/1': 'One', '/foo/1/bar': 'Bar', '/foo/1/bar/fiz': 'Fiz' }; const findChildren = () => { breadcrumb = breadcrumbWrapper.find('Breadcrumb'); breadcrumbItem = breadcrumbWrapper.find('BreadcrumbItem'); breadcrumbHeading = breadcrumbWrapper.find('BreadcrumbHeading'); }; test('initially renders succesfully', () => { breadcrumbWrapper = mount( ); findChildren(); expect(breadcrumb).toHaveLength(1); expect(breadcrumbItem).toHaveLength(2); expect(breadcrumbHeading).toHaveLength(1); expect(breadcrumbItem.first().text()).toBe('Foo'); expect(breadcrumbItem.last().text()).toBe('One'); expect(breadcrumbHeading.text()).toBe('Bar'); breadcrumbWrapper.unmount(); }); test('renders breadcrumb items defined in breadcrumbConfig', () => { const routes = [ ['/fo', 0], ['/foo', 0], ['/foo/1', 1], ['/foo/baz', 1], ['/foo/1/bar', 2], ['/foo/1/bar/fiz', 3], ]; routes.forEach(([location, crumbLength]) => { breadcrumbWrapper = mount( ); expect(breadcrumbWrapper.find('BreadcrumbItem')).toHaveLength(crumbLength); breadcrumbWrapper.unmount(); }); }); });