2018-09-18 16:06:55 +00:00
|
|
|
import { getPort, loadFixture, Nuxt } from '../utils'
|
|
|
|
|
|
|
|
let port
|
2023-10-16 21:23:38 +00:00
|
|
|
const url = route => 'http://127.0.0.1:' + port + route
|
2018-09-18 16:06:55 +00:00
|
|
|
|
|
|
|
let nuxt = null
|
|
|
|
|
2021-02-07 20:54:07 +00:00
|
|
|
describe('plugins', () => {
|
2018-09-18 16:06:55 +00:00
|
|
|
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()
|
2023-10-16 21:23:38 +00:00
|
|
|
await nuxt.server.listen(port, '127.0.0.1')
|
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()
|
|
|
|
})
|
2020-04-21 12:40:42 +00:00
|
|
|
test('inject should add to context and prototypes', async () => {
|
|
|
|
const window = await nuxt.server.renderAndGetWindow(url('/?injectValue=foo'))
|
|
|
|
// inject('injectedProperty', 'bar')
|
|
|
|
await expect(window.$nuxt.$injectedProperty).toBe('bar')
|
|
|
|
await expect(window.$nuxt.context.$injectedProperty).toBe('bar')
|
|
|
|
await expect(window.$nuxt.context.app.$injectedProperty).toBe('bar')
|
|
|
|
await expect(window.$nuxt.$store.$injectedProperty).toBe('bar')
|
|
|
|
})
|
2018-10-27 16:41:42 +00:00
|
|
|
|
2018-09-18 16:06:55 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
afterAll(async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
|
|
|
})
|