Skip to content

Commit

Permalink
Add test for data preload link
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 7, 2020
1 parent e5db1bb commit 310e98d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/integration/prerender/test/index.test.js
Expand Up @@ -255,13 +255,16 @@ const runTests = (dev = false) => {
const html = await renderViaHTTP(appPort, '/blog/post-1')

if (dev) {
expect(
JSON.parse(
cheerio
.load(html)('#__NEXT_DATA__')
.text()
).isFallback
).toBe(true)
const $ = cheerio.load(html)
expect(JSON.parse($('#__NEXT_DATA__').text()).isFallback).toBe(true)

const preloadLink = Array.from($('link[rel=preload]')).find(el =>
el.attribs.href.endsWith('post-1.json')
)

expect(preloadLink.attribs.href).toBe(
`/_next/data/${buildId}/blog/post-1.json`
)
} else {
expect(html).toMatch(/Post:.*?post-1/)
}
Expand Down

0 comments on commit 310e98d

Please sign in to comment.