1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/test/integration.test.js
2016-12-02 10:35:07 +09:00

47 lines
1.4 KiB
JavaScript

import test from 'ava'
import { join } from 'path'
import build from '../server/build'
import { render as _render } from '../server/render'
const dir = join(__dirname, 'fixtures', 'basic')
test.before(() => build(dir))
test('renders a stateless component', async t => {
const html = await render('/stateless')
t.true(html.includes('<meta charset="utf-8" class="next-head"/>'))
t.true(html.includes('<h1>My component!</h1>'))
})
test('renders a stateful component', async t => {
const html = await render('/stateful')
t.true(html.includes('<div><p>The answer is 42</p></div>'))
})
test('header helper renders header information', async t => {
const html = await (render('/head'))
t.true(html.includes('<meta charset="iso-8859-5" class="next-head"/>'))
t.true(html.includes('<meta content="my meta" class="next-head"/>'))
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
})
test('css helper renders styles', async t => {
const html = await render('/css')
t.regex(html, /\.css-\w+/)
t.regex(html, /<div class="css-\w+">This is red<\/div>/)
})
test('renders properties populated asynchronously', async t => {
const html = await render('/async-props')
t.true(html.includes('<p>Diego Milito</p>'))
})
test('renders a link component', async t => {
const html = await render('/link')
t.true(html.includes('<a href="/about">About</a>'))
})
function render (url, ctx) {
return _render(url, ctx, { dir, staticMarkup: true })
}