|
|
@@ -6,6 +6,7 @@ import {
|
|
|
hasInjectionContext,
|
|
|
inject,
|
|
|
nextTick,
|
|
|
+ onMounted,
|
|
|
provide,
|
|
|
reactive,
|
|
|
readonly,
|
|
|
@@ -372,4 +373,46 @@ describe('api: provide/inject', () => {
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe('warnings for incorrect usage', () => {
|
|
|
+ it('should warn when inject() is called outside setup', () => {
|
|
|
+ inject('foo', 'bar')
|
|
|
+ expect(`inject() can only be used`).toHaveBeenWarned()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should warn when provide() is called outside setup', () => {
|
|
|
+ provide('foo', 'bar')
|
|
|
+ expect(`provide() can only be used`).toHaveBeenWarned()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should warn when provide() is called from a render function', () => {
|
|
|
+ const Provider = {
|
|
|
+ setup() {
|
|
|
+ return () => {
|
|
|
+ provide('foo', 'bar')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ const root = nodeOps.createElement('div')
|
|
|
+ render(h(Provider), root)
|
|
|
+ expect(`provide() can only be used`).toHaveBeenWarned()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should warn when provide() is called from onMounted', () => {
|
|
|
+ const Provider = {
|
|
|
+ setup() {
|
|
|
+ onMounted(() => {
|
|
|
+ provide('foo', 'bar')
|
|
|
+ })
|
|
|
+
|
|
|
+ return () => null
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ const root = nodeOps.createElement('div')
|
|
|
+ render(h(Provider), root)
|
|
|
+ expect(`provide() can only be used`).toHaveBeenWarned()
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|