test: add test for inject in context (#7252)

This commit is contained in:
Sébastien Chopin 2020-04-21 14:40:42 +02:00 committed by GitHub
parent 67b8020c11
commit 76c40e3ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -35,6 +35,14 @@ describe('with-config', () => {
// inject('injectedProperty', '') // inject('injectedProperty', '')
await expect(nuxt.renderRoute('/?injectValue=empty')).resolves.not.toThrowError() await expect(nuxt.renderRoute('/?injectValue=empty')).resolves.not.toThrowError()
}) })
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')
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
afterAll(async () => { afterAll(async () => {

View File

@ -9,7 +9,8 @@ export default ({ route, params }, inject) => {
null: null, null: null,
false: false, false: false,
0: 0, 0: 0,
empty: '' empty: '',
foo: 'bar'
} }
const value = map[injectValue] const value = map[injectValue]
inject(key, value) inject(key, value)