|
| 1 | +import expect from 'expect' |
| 2 | +import React from 'react' |
| 3 | +import { render, unmountComponentAtNode } from 'react-dom' |
| 4 | +import Match from '../Match' |
| 5 | +import Miss from '../Miss' |
| 6 | +import MatchGroup from '../MatchGroup' |
| 7 | +import Router from '../MemoryRouter' |
| 8 | + |
| 9 | +describe('MatchGroup', () => { |
| 10 | + const div = document.createElement('div') |
| 11 | + |
| 12 | + const HOME = 'HOME' |
| 13 | + const Home = () => <div>{HOME}</div> |
| 14 | + |
| 15 | + const FOO = 'FOO' |
| 16 | + const Foo = () => <div>{FOO}</div> |
| 17 | + |
| 18 | + const NO_MATCH = 'NO_MATCH' |
| 19 | + const NoMatch = () => <div>{NO_MATCH}</div> |
| 20 | + |
| 21 | + const App = ({ pathname }) => ( |
| 22 | + <Router initialEntries={[{ pathname }]}> |
| 23 | + <MatchGroup> |
| 24 | + <Match exactly pattern="/" component={Home} /> |
| 25 | + <Match pattern="/foo" component={Foo} /> |
| 26 | + <Miss component={NoMatch} /> |
| 27 | + </MatchGroup> |
| 28 | + </Router> |
| 29 | + ) |
| 30 | + |
| 31 | + afterEach(() => unmountComponentAtNode(div)) |
| 32 | + |
| 33 | + it('renders the first matching child', () => { |
| 34 | + render(<App pathname="/"/>, div, () => { |
| 35 | + expect(div.innerHTML).toContain(HOME) |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + it('renders the first matching child that is not the first child', () => { |
| 40 | + render(<App pathname="/foo"/>, div, () => { |
| 41 | + expect(div.innerHTML).toContain(FOO) |
| 42 | + }) |
| 43 | + }) |
| 44 | + |
| 45 | + it('renders a miss when nothing else matches', () => { |
| 46 | + render(<App pathname="/no-match"/>, div, () => { |
| 47 | + expect(div.innerHTML).toContain(NO_MATCH) |
| 48 | + }) |
| 49 | + }) |
| 50 | +}) |
| 51 | + |
0 commit comments