mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-13 08:32:26 +03:00
throw console warning if option[label] does not exist, prevents TypeError from breaking page
closes #155
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-select",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.1",
|
||||
"description": "A native Vue.js component that provides similar functionality to Select2 without the overhead of jQuery.",
|
||||
"author": "Jeff Sagal <sagalbot@gmail.com>",
|
||||
"private": false,
|
||||
|
||||
@@ -715,8 +715,10 @@
|
||||
*/
|
||||
filteredOptions() {
|
||||
let options = this.mutableOptions.filter((option) => {
|
||||
if (typeof option === 'object') {
|
||||
if (typeof option === 'object' && option.hasOwnProperty(this.label)) {
|
||||
return option[this.label].toLowerCase().indexOf(this.search.toLowerCase()) > -1
|
||||
} else if (typeof option === 'object' && !option.hasOwnProperty(this.label)) {
|
||||
return console.warn(`[vue-select warn]: Label key "option.${this.label}" does not exist in options object.\nhttp://sagalbot.github.io/vue-select/#ex-labels`)
|
||||
}
|
||||
return option.toLowerCase().indexOf(this.search.toLowerCase()) > -1
|
||||
})
|
||||
|
||||
@@ -679,6 +679,20 @@ describe('Select.vue', () => {
|
||||
expect(vm.$children[0].$refs.toggle.querySelector('.selected-tag').textContent).toContain('Baz')
|
||||
})
|
||||
|
||||
it('will console.warn when options contain objects without a valid label key', (done) => {
|
||||
spyOn(console, 'warn')
|
||||
const vm = new Vue({
|
||||
template: '<div><v-select :options="[{}]"></v-select></div>',
|
||||
}).$mount()
|
||||
Vue.nextTick(() => {
|
||||
expect(console.warn).toHaveBeenCalledWith(
|
||||
'[vue-select warn]: Label key "option.label" does not exist in options object.' +
|
||||
'\nhttp://sagalbot.github.io/vue-select/#ex-labels'
|
||||
)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should display a placeholder if the value is empty', (done) => {
|
||||
const vm = new Vue({
|
||||
template: '<div><v-select :options="options" placeholder="foo"></v-select></div>',
|
||||
|
||||
Reference in New Issue
Block a user