Skip to content

Failing test for <Miss /> with 'Blocker' component #4047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions modules/__tests__/Miss-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import expect from 'expect'
import React from 'react'
import Miss from '../Miss'
import Match from '../Match'
import Redirect from '../Redirect'
import { render, unmountComponentAtNode } from 'react-dom'
import MemoryRouter from '../MemoryRouter'

describe('Miss', () => {
const TEXT = 'TEXT'
const loc = { pathname: '/', search: '', hash: '', state: TEXT }

const renderRouter = (element, location) => (
<MemoryRouter initialEntries={[location]} initialIndex={0}>
{element}
</MemoryRouter>
)

it('renders a Component prop', (done) => {
const div = document.createElement('div')
const Page = () => <div>{TEXT}</div>
Expand Down Expand Up @@ -42,9 +49,10 @@ describe('Miss', () => {
const MATCH = 'MATCH'

const App = ({ location }) => (
<MemoryRouter initialEntries={[location]} initialIndex={0}>
<Match pattern='/parent' component={Parent} />
</MemoryRouter>
renderRouter(
<Match pattern='/parent' component={Parent} />,
location
)
)

const Parent = () => (
Expand All @@ -61,6 +69,7 @@ describe('Miss', () => {
render(<App location={nestedLoc} />, div, () => {
expect(div.innerHTML).toNotContain(TEXT)
expect(div.innerHTML).toContain(MATCH)
unmountComponentAtNode(div)
done()
})
})
Expand All @@ -72,8 +81,42 @@ describe('Miss', () => {
render(<App location={nestedLoc} />, div, () => {
expect(div.innerHTML).toContain(TEXT)
expect(div.innerHTML).toNotContain(MATCH)
unmountComponentAtNode(div)
done()
})
})
})

describe('FAILING MISS TESTS', () => {
it('does not update when a `blocker` component is rendered', (done) => {
const div = document.createElement('div')

class Blocker extends React.Component {
shouldComponentUpdate() { return false }
render() { return <App /> }
}
const Home = () => (
<Redirect to='/404-it' />
)
const App = () => (
<div>
<Match pattern='/' exactly component={Home} />
<Miss component={() => <p>NotFound</p>} />
</div>
)

render(
renderRouter(
<Blocker />,
{ pathname: '/' }
),
div,
() => {
expect(div.innerHTML).toContain('NotFound')
unmountComponentAtNode(div)
done()
}
)
})
})
})