From 310e98d5ba0fd95d5d7a7b5b0e6c55e94bf4c783 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 6 Feb 2020 21:36:56 -0600 Subject: [PATCH] Add test for data preload link --- test/integration/prerender/test/index.test.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index a1bad06c53b7c..8a3014c483e3b 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -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/) }