2018-09-18 16:06:55 +00:00
|
|
|
import { getPort, loadFixture, Nuxt } from '../utils'
|
|
|
|
|
|
|
|
let port
|
|
|
|
const url = route => 'http://localhost:' + port + route
|
|
|
|
|
|
|
|
let nuxt = null
|
|
|
|
|
|
|
|
describe('with-config', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
const config = await loadFixture('basic')
|
|
|
|
nuxt = new Nuxt(config)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
|
|
|
|
2018-09-18 16:06:55 +00:00
|
|
|
port = await getPort()
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.listen(port, 'localhost')
|
2018-09-18 16:06:55 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('/', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const window = await nuxt.server.renderAndGetWindow(url('/'))
|
2018-09-18 16:06:55 +00:00
|
|
|
expect(window.__test_plugin).toBe(true)
|
|
|
|
})
|
|
|
|
|
2018-10-27 16:41:42 +00:00
|
|
|
test('inject fails if value is undefined', async () => {
|
|
|
|
// inject('injectedProperty', undefined)
|
2020-02-29 19:16:43 +00:00
|
|
|
await expect(nuxt.renderRoute('/?injectValue=undefined')).rejects.toThrowError('inject(\'injectedProperty\', value) has no value provided')
|
2018-10-27 16:41:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('inject succeeds if value is defined but evaluates to false', async () => {
|
|
|
|
// inject('injectedProperty', null)
|
|
|
|
await expect(nuxt.renderRoute('/?injectValue=null')).resolves.not.toThrowError()
|
|
|
|
// inject('injectedProperty', false)
|
|
|
|
await expect(nuxt.renderRoute('/?injectValue=false')).resolves.not.toThrowError()
|
|
|
|
// inject('injectedProperty', 0)
|
|
|
|
await expect(nuxt.renderRoute('/?injectValue=0')).resolves.not.toThrowError()
|
|
|
|
// inject('injectedProperty', '')
|
|
|
|
await expect(nuxt.renderRoute('/?injectValue=empty')).resolves.not.toThrowError()
|
|
|
|
})
|
|
|
|
|
2018-09-18 16:06:55 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
afterAll(async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
|
|
|
})
|