From 76c40e3ffde9bba3bab55a5b0776d9aa5cb16251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 21 Apr 2020 14:40:42 +0200 Subject: [PATCH] test: add test for inject in context (#7252) --- test/dev/basic.plugins.test.js | 8 ++++++++ test/fixtures/basic/plugins/inject.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/dev/basic.plugins.test.js b/test/dev/basic.plugins.test.js index 39ddbdc693..f5cee2e448 100644 --- a/test/dev/basic.plugins.test.js +++ b/test/dev/basic.plugins.test.js @@ -35,6 +35,14 @@ describe('with-config', () => { // inject('injectedProperty', '') 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 afterAll(async () => { diff --git a/test/fixtures/basic/plugins/inject.js b/test/fixtures/basic/plugins/inject.js index 65d4821edc..d9cbae08d5 100644 --- a/test/fixtures/basic/plugins/inject.js +++ b/test/fixtures/basic/plugins/inject.js @@ -9,7 +9,8 @@ export default ({ route, params }, inject) => { null: null, false: false, 0: 0, - empty: '' + empty: '', + foo: 'bar' } const value = map[injectValue] inject(key, value)