/* eslint-env jest */ import cheerio from 'cheerio' import { nextTestSetup } from 'e2e-utils' import { renderViaHTTP } from 'next-test-utils' import path from 'path' const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18 describe('Client Navigation rendering ', () => { const { next } = nextTestSetup({ files: path.join(__dirname, 'fixture'), }) function render( pathname: Parameters[1], query?: Parameters[2] ) { return renderViaHTTP(next.appPort, pathname, query) } it('should handle undefined prop in head server-side', async () => { const html = await render('/head') const $ = cheerio.load(html) const value = 'content' in $('meta[name="empty-content"]').attr() expect(value).toBe(false) }) // default-head contains an empty . test('header renders default charset', async () => { const html = await render('/default-head') expect(html).toContain('') expect(html).toContain('next-head, but only once.') }) test('header renders default viewport', async () => { const html = await render('/default-head') expect(html).toContain( '' ) }) test('header helper renders header information', async () => { const html = await render('/head') expect(html).toContain('') expect(html).toContain('') expect(html).toContain( '' ) expect(html).toContain('I can have meta tags') }) test('header helper dedupes tags', async () => { const html = await render('/head') expect(html).toContain('') expect(html).not.toContain('') expect(html).toContain( '' ) // Should contain only one viewport expect(html.match(/') expect(html).toContain( '' ) const dedupeLink = '' expect(html).toContain(dedupeLink) expect( html.substring(html.indexOf(dedupeLink) + dedupeLink.length) ).not.toContain('' ) expect(html).not.toContain( ' { const html = await render('/head-duplicate-default-keys') // Expect exactly one `charSet` expect((html.match(/charSet=/g) || []).length).toBe(1) // Expect exactly one `viewport` expect((html.match(/name="viewport"/g) || []).length).toBe(1) expect(html).toContain('') expect(html).toContain( '' ) }) test('header helper avoids dedupe of specific tags', async () => { const html = await render('/head') console.log(html) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).not.toContain('' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) expect(html).toContain( '' ) }) test('header helper avoids dedupe of meta tags with the same name if they use unique keys', async () => { const html = await render('/head') expect(html).toContain( '' ) expect(html).toContain( '' ) }) test('header helper renders Fragment children', async () => { const html = await render('/head') expect(html).toContain('Fragment title') expect(html).toContain('') }) test('header helper renders boolean attributes correctly children', async () => { const html = await render('/head') expect(html).toContain( '