test: redirect to external url

This commit is contained in:
Clark Du 2017-11-28 17:10:44 +08:00
parent 21f9145309
commit 3020af7c38
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
3 changed files with 33 additions and 0 deletions

View File

@ -143,6 +143,15 @@ test('/redirect2', async t => {
t.is(await page.$text('h1'), 'Index page')
})
test('/redirect3', async t => {
// New page for redirecting to external link.
const page = await browser.page(url('/'))
await page.nuxt.navigate('/redirect3', false)
await page.waitForFunction(() => window.location.href === 'https://nuxtjs.org/')
page.close()
t.pass()
})
test('/no-ssr', async t => {
await page.nuxt.navigate('/no-ssr')

View File

@ -117,6 +117,19 @@ test('/redirect -> check redirected source', async t => {
t.true(html.includes('<h1>Index page</h1>'))
})
test('/redirect -> external link', async t => {
const headers = {}
const { html } = await nuxt.renderRoute('/redirect3', {
res: {
setHeader(k, v) {
headers[k] = v
}
}
})
t.is(headers.Location, 'https://nuxtjs.org')
t.true(html.includes('<div>redirecting.</div>'))
})
test('/special-state -> check window.__NUXT__.test = true', async t => {
const window = await nuxt.renderAndGetWindow(url('/special-state'))
t.is(window.document.title, 'Nuxt.js')

11
test/fixtures/basic/pages/redirect3.vue vendored Normal file
View File

@ -0,0 +1,11 @@
<template>
<div>Redirecting...</div>
</template>
<script>
export default {
fetch({ redirect }) {
return redirect('https://nuxtjs.org/')
}
}
</script>