add object-typed value test

pull/5899/merge
Leopoldthecoder 2017-07-20 12:27:55 +08:00 committed by 杨奕
parent 40a873e93e
commit daa4f83e4f
3 changed files with 49 additions and 3 deletions

View File

@ -50,7 +50,7 @@
computed: { computed: {
isObject() { isObject() {
const type = typeof this.value; const type = typeof this.value;
return type !== 'string' && type !== 'number'; return type !== 'string' && type !== 'number' && type !== 'boolean';
}, },
currentLabel() { currentLabel() {

View File

@ -366,7 +366,7 @@
getOption(value) { getOption(value) {
let option; let option;
const type = typeof value; const type = typeof value;
const isObject = type !== 'string' && type !== 'number'; const isObject = type !== 'string' && type !== 'number' && type !== 'boolean';
for (let i = this.cachedOptions.length - 1; i >= 0; i--) { for (let i = this.cachedOptions.length - 1; i >= 0; i--) {
const cachedOption = this.cachedOptions[i]; const cachedOption = this.cachedOptions[i];
const isEqual = isObject const isEqual = isObject
@ -529,7 +529,7 @@
getValueIndex(arr = [], value) { getValueIndex(arr = [], value) {
const type = typeof value; const type = typeof value;
const isObject = type !== 'string' && type !== 'number'; const isObject = type !== 'string' && type !== 'number' && type !== 'boolean';
if (!isObject) { if (!isObject) {
return arr.indexOf(value); return arr.indexOf(value);
} else { } else {

View File

@ -113,6 +113,7 @@ describe('Select', () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:label="item.label" :label="item.label"
:key="item.value"
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
@ -147,6 +148,7 @@ describe('Select', () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:label="item.label" :label="item.label"
:key="item.value"
:value="item.value"> :value="item.value">
<p>{{item.label}} {{item.value}}</p> <p>{{item.label}} {{item.value}}</p>
</el-option> </el-option>
@ -226,6 +228,7 @@ describe('Select', () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:label="item.label" :label="item.label"
:key="item.value"
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
@ -285,6 +288,44 @@ describe('Select', () => {
}, 100); }, 100);
}); });
it('object typed value', done => {
vm = createVue({
template: `
<div>
<el-select v-model="value" value-key="id">
<el-option
v-for="item in options"
:label="item.label"
:key="item.id"
:value="item">
</el-option>
</el-select>
</div>
`,
data() {
return {
options: [{
id: 1,
label: 'label1'
}, {
id: 2,
label: 'label2'
}],
value: {
id: 1,
label: 'label1'
}
};
}
}, true);
setTimeout(() => {
expect(vm.$el.querySelector('.el-input__inner').value).to.equal('label1');
expect(vm.$el.querySelector('.el-select-dropdown__item').classList.contains('selected'));
done();
}, 100);
});
it('custom el-option template', () => { it('custom el-option template', () => {
vm = createVue({ vm = createVue({
template: ` template: `
@ -293,6 +334,7 @@ describe('Select', () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:label="item.label" :label="item.label"
:key="item.value"
:value="item.value"> :value="item.value">
<p>{{item.label}} {{item.value}}</p> <p>{{item.label}} {{item.value}}</p>
</el-option> </el-option>
@ -320,11 +362,13 @@ describe('Select', () => {
<el-select v-model="value"> <el-select v-model="value">
<el-option-group <el-option-group
v-for="group in options" v-for="group in options"
:key="group.label"
:disabled="group.disabled" :disabled="group.disabled"
:label="group.label"> :label="group.label">
<el-option <el-option
v-for="item in group.options" v-for="item in group.options"
:label="item.label" :label="item.label"
:key="item.value"
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-option-group> </el-option-group>
@ -416,6 +460,7 @@ describe('Select', () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:label="item" :label="item"
:key="item.value"
:value="item" :value="item"
/> />
</el-select> </el-select>
@ -504,6 +549,7 @@ describe('Select', () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:label="item.label" :label="item.label"
:key="item.value"
:value="item.value"> :value="item.value">
<p>{{item.label}} {{item.value}}</p> <p>{{item.label}} {{item.value}}</p>
</el-option> </el-option>