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: {
isObject() {
const type = typeof this.value;
return type !== 'string' && type !== 'number';
return type !== 'string' && type !== 'number' && type !== 'boolean';
},
currentLabel() {

View File

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

View File

@ -113,6 +113,7 @@ describe('Select', () => {
<el-option
v-for="item in options"
:label="item.label"
:key="item.value"
:value="item.value">
</el-option>
</el-select>
@ -147,6 +148,7 @@ describe('Select', () => {
<el-option
v-for="item in options"
:label="item.label"
:key="item.value"
:value="item.value">
<p>{{item.label}} {{item.value}}</p>
</el-option>
@ -226,6 +228,7 @@ describe('Select', () => {
<el-option
v-for="item in options"
:label="item.label"
:key="item.value"
:value="item.value">
</el-option>
</el-select>
@ -285,6 +288,44 @@ describe('Select', () => {
}, 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', () => {
vm = createVue({
template: `
@ -293,6 +334,7 @@ describe('Select', () => {
<el-option
v-for="item in options"
:label="item.label"
:key="item.value"
:value="item.value">
<p>{{item.label}} {{item.value}}</p>
</el-option>
@ -320,11 +362,13 @@ describe('Select', () => {
<el-select v-model="value">
<el-option-group
v-for="group in options"
:key="group.label"
:disabled="group.disabled"
:label="group.label">
<el-option
v-for="item in group.options"
:label="item.label"
:key="item.value"
:value="item.value">
</el-option>
</el-option-group>
@ -416,6 +460,7 @@ describe('Select', () => {
<el-option
v-for="item in options"
:label="item"
:key="item.value"
:value="item"
/>
</el-select>
@ -504,6 +549,7 @@ describe('Select', () => {
<el-option
v-for="item in options"
:label="item.label"
:key="item.value"
:value="item.value">
<p>{{item.label}} {{item.value}}</p>
</el-option>