1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add a test case for client side routing for next export.

This commit is contained in:
Arunoda Susiripala 2017-05-11 08:52:28 -07:00
parent b18ecc925b
commit 880eb4caff
2 changed files with 30 additions and 10 deletions

View file

@ -1,27 +1,23 @@
import React from 'react' import React from 'react'
import Link from 'next/link' import Link from 'next/link'
export default class Counter extends React.Component { let counter = 0
constructor (...args) {
super(...args)
this.state = { count: 0 }
}
export default class Counter extends React.Component {
increaseCounter () { increaseCounter () {
const { count } = this.state counter++
this.setState({ count: count + 1 }) this.forceUpdate()
} }
render () { render () {
const { count } = this.state
return ( return (
<div id='counter-page'> <div id='counter-page'>
<div> <div>
<Link href='/'> <Link href='/'>
<a>Go Back</a> <a id='go-back'>Go Back</a>
</Link> </Link>
</div> </div>
<p>Counter: {count}</p> <p>Counter: {counter}</p>
<button <button
id='counter-increase' id='counter-increase'
onClick={() => this.increaseCounter()} onClick={() => this.increaseCounter()}

View file

@ -68,5 +68,29 @@ export default function (context) {
expect(text).toBe('next export is nice') expect(text).toBe('next export is nice')
browser.close() browser.close()
}) })
it('should support client side naviagtion', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#counter').click()
.waitForElementByCss('#counter-page')
.elementByCss('#counter-increase').click()
.elementByCss('#counter-increase').click()
.elementByCss('#counter-page p').text()
expect(text).toBe('Counter: 2')
// let's go back and come again to this page:
const textNow = await browser
.elementByCss('#go-back').click()
.waitForElementByCss('#home-page')
.elementByCss('#counter').click()
.waitForElementByCss('#counter-page')
.elementByCss('#counter-page p').text()
expect(textNow).toBe('Counter: 2')
browser.close()
})
}) })
} }