forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrendering.js
More file actions
97 lines (78 loc) · 3.26 KB
/
Copy pathrendering.js
File metadata and controls
97 lines (78 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* global describe, test, it, expect */
import cheerio from 'cheerio'
export default function ({ app }, suiteName, render) {
async function get$ (path, query) {
const html = await render(path, query)
return cheerio.load(html)
}
describe(suiteName, () => {
test('renders a stateless component', async () => {
const html = await render('/stateless')
expect(html.includes('<meta charSet="utf-8" class="next-head"/>')).toBeTruthy()
expect(html.includes('My component!')).toBeTruthy()
})
test('renders a stateful component', async () => {
const $ = await get$('/stateful')
const answer = $('#answer')
expect(answer.text()).toBe('The answer is 42')
})
test('header helper renders header information', async () => {
const html = await (render('/head'))
expect(html.includes('<meta charSet="iso-8859-5" class="next-head"/>')).toBeTruthy()
expect(html.includes('<meta content="my meta" class="next-head"/>')).toBeTruthy()
expect(html.includes('I can haz meta tags')).toBeTruthy()
})
test('renders styled jsx', async () => {
const $ = await get$('/styled-jsx')
const styleId = $('#blue-box').attr('class')
const style = $('style')
expect(style.text().includes(`p.${styleId}{color:blue`)).toBeTruthy()
})
test('renders properties populated asynchronously', async () => {
const html = await render('/async-props')
expect(html.includes('Diego Milito')).toBeTruthy()
})
test('renders a link component', async () => {
const $ = await get$('/link')
const link = $('a[href="/about"]')
expect(link.text()).toBe('About')
})
test('getInitialProps resolves to null', async () => {
const $ = await get$('/empty-get-initial-props')
const expectedErrorMessage = '"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.'
expect($('pre').text().includes(expectedErrorMessage)).toBeTruthy()
})
test('allows to import .json files', async () => {
const html = await render('/json')
expect(html.includes('Zeit')).toBeTruthy()
})
test('default export is not a React Component', async () => {
const $ = await get$('/no-default-export')
const pre = $('pre')
expect(pre.text()).toMatch(/The default export is not a React Component/)
})
test('error', async () => {
const $ = await get$('/error')
expect($('pre').text()).toMatch(/This is an expected error/)
})
test('asPath', async () => {
const $ = await get$('/nav/as-path', { aa: 10 })
expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10')
})
test('error 404', async () => {
const $ = await get$('/non-existent')
expect($('h1').text()).toBe('404')
expect($('h2').text()).toBe('This page could not be found.')
})
describe('with the HOC based router', () => {
it('should navigate as expected', async () => {
const $ = await get$('/nav/with-hoc')
expect($('#pathname').text()).toBe('Current path: /nav/with-hoc')
})
it('should include asPath', async () => {
const $ = await get$('/nav/with-hoc')
expect($('#asPath').text()).toBe('Current asPath: /nav/with-hoc')
})
})
})
}