Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ function normalizeInject (options: Object, vm: ?Component) {
const normalized = options.inject = {}
if (Array.isArray(inject)) {
for (let i = 0; i < inject.length; i++) {
if (typeof inject[i] !== 'string') {
if (process.env.NODE_ENV !== 'production') {
warn(
`Invalid value for option "inject": expected an Array of string, ` +
`but found ${toRawType(inject[i])}.`,
vm
);
}
continue;
}
normalized[inject[i]] = { from: inject[i] }
}
} else if (isPlainObject(inject)) {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/features/options/inject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,19 @@ describe('Options provide/inject', () => {
})
expect(`Injection "constructor" not found`).toHaveBeenWarned()
})

it('should warn when inject with none-string Array', () => {
const obj = { a: 1 }
const vm = new Vue({
template: `<child/>`,
provide: {},
components: {
child: {
inject: [obj],
template: `<div>{{ 123 }}</div>`,
},
},
}).$mount()
expect(`Invalid value for option "inject": expected an Array of string`).toHaveBeenWarned()
})
})