Skip to content

Commit

Permalink
Add routeChangeComplete integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
HaNdTriX committed Sep 3, 2018
1 parent 2eeebac commit 529d386
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/integration/with-router/components/header-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class HeaderNav extends React.Component {
this.state = {
activeURL: router.asPath,
activeURLTopLevelRouterDeprecatedBehavior: router.asPath,
activeURLTopLevelRouter: router.asPath
activeURLTopLevelRouter: router.asPath,
title: null
}
}

Expand All @@ -32,7 +33,8 @@ class HeaderNav extends React.Component {

handleRouteChange = url => {
this.setState({
activeURL: url
activeURL: url,
title: window.document.title
})
};

Expand Down Expand Up @@ -60,6 +62,8 @@ class HeaderNav extends React.Component {
</Link>
))
}

<div className='title'>{this.state.title}</div>
</nav>
)
}
Expand Down
4 changes: 4 additions & 0 deletions test/integration/with-router/pages/a.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { withRouter } from 'next/router'
import Head from 'next/head'

class PageA extends React.Component {
goToB () {
Expand All @@ -9,6 +10,9 @@ class PageA extends React.Component {
render () {
return (
<div id='page-a'>
<Head>
<title>page-a</title>
</Head>
<button onClick={() => this.goToB()}>Go to B</button>
</div>
)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/with-router/pages/b.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as React from 'react'
import Head from 'next/head'

class PageB extends React.Component {
render () {
return (
<div id='page-b'>
<Head>
<title>page-b</title>
</Head>
<p>Page B!</p>
</div>
)
Expand Down
16 changes: 16 additions & 0 deletions test/integration/with-router/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,20 @@ describe('withRouter', () => {

browser.close()
})

it('fires routeChangeComplete after head update', async () => {
const browser = await webdriver(appPort, '/a')
await browser.waitForElementByCss('#page-a')

let title = await browser.elementByCss('.title').text()
expect(title).toBe('')

await browser.elementByCss('button').click()
await browser.waitForElementByCss('#page-b')

title = await browser.elementByCss('.title').text()
expect(title).toBe('page-b')

browser.close()
})
})

0 comments on commit 529d386

Please sign in to comment.