mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
eslint fixes
This commit is contained in:
+49
-45
@@ -1,57 +1,61 @@
|
||||
import VueSelect from "../../src/components/Select";
|
||||
import { shallowMount } from "@vue/test-utils";
|
||||
import { selectWithProps } from "../helpers";
|
||||
import VueSelect from '../../src/components/Select'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import { selectWithProps } from '../helpers'
|
||||
|
||||
describe("Labels", () => {
|
||||
it("can generate labels using a custom label key", () => {
|
||||
describe('Labels', () => {
|
||||
it('can generate labels using a custom label key', () => {
|
||||
const Select = selectWithProps({
|
||||
options: [{ name: "Foo" }],
|
||||
label: "name",
|
||||
value: { name: "Foo" }
|
||||
});
|
||||
expect(Select.find(".vs__selected").text()).toBe("Foo");
|
||||
});
|
||||
options: [{ name: 'Foo' }],
|
||||
label: 'name',
|
||||
value: { name: 'Foo' },
|
||||
})
|
||||
expect(Select.find('.vs__selected').text()).toBe('Foo')
|
||||
})
|
||||
|
||||
it("will console.warn when options contain objects without a valid label key", async () => {
|
||||
const spy = jest.spyOn(console, "warn").mockImplementation(() => {});
|
||||
it('will console.warn when options contain objects without a valid label key', async () => {
|
||||
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
const Select = selectWithProps({
|
||||
options: [{}]
|
||||
});
|
||||
options: [{}],
|
||||
})
|
||||
|
||||
Select.vm.open = true;
|
||||
await Select.vm.$nextTick();
|
||||
Select.vm.open = true
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
'[vue-select warn]: Label key "option.label" does not exist in options object {}.' +
|
||||
"\nhttps://vue-select.org/api/props.html#getoptionlabel"
|
||||
);
|
||||
});
|
||||
'\nhttps://vue-select.org/api/props.html#getoptionlabel'
|
||||
)
|
||||
})
|
||||
|
||||
it("should display a placeholder if the value is empty", () => {
|
||||
it('should display a placeholder if the value is empty', () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: {
|
||||
options: ["one"]
|
||||
options: ['one'],
|
||||
},
|
||||
attrs: {
|
||||
placeholder: "foo"
|
||||
}
|
||||
});
|
||||
placeholder: 'foo',
|
||||
},
|
||||
})
|
||||
|
||||
expect(Select.vm.searchPlaceholder).toEqual("foo");
|
||||
Select.vm.$data._value = "one";
|
||||
expect(Select.vm.searchPlaceholder).not.toBeDefined();
|
||||
});
|
||||
expect(Select.vm.searchPlaceholder).toEqual('foo')
|
||||
Select.vm.$data._value = 'one'
|
||||
expect(Select.vm.searchPlaceholder).not.toBeDefined()
|
||||
})
|
||||
|
||||
describe('getOptionLabel', () => {
|
||||
it('will return undefined if the option lacks the label key', () => {
|
||||
const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({ label: 'label' });
|
||||
expect(getOptionLabel({name: 'vue'})).toEqual(undefined);
|
||||
});
|
||||
const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({
|
||||
label: 'label',
|
||||
})
|
||||
expect(getOptionLabel({ name: 'vue' })).toEqual(undefined)
|
||||
})
|
||||
|
||||
it('will return a string value for a valid key', () => {
|
||||
const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({ label: 'label' });
|
||||
expect(getOptionLabel({label: 'vue'})).toEqual('vue');
|
||||
});
|
||||
const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({
|
||||
label: 'label',
|
||||
})
|
||||
expect(getOptionLabel({ label: 'vue' })).toEqual('vue')
|
||||
})
|
||||
|
||||
/**
|
||||
* this test fails because of a bug where Vue executes the default contents
|
||||
@@ -60,22 +64,22 @@ describe("Labels", () => {
|
||||
* @see https://github.com/vuejs/vue/pull/10229
|
||||
*/
|
||||
xit('will not call getOptionLabel if both scoped option slots are used and a filter is provided', () => {
|
||||
const spy = spyOn(VueSelect.props.getOptionLabel, 'default');
|
||||
const spy = spyOn(VueSelect.props.getOptionLabel, 'default')
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: {
|
||||
options: [{name: 'one'}],
|
||||
options: [{ name: 'one' }],
|
||||
filter: () => {},
|
||||
},
|
||||
scopedSlots: {
|
||||
'option': '<span class="option">{{ props.name }}</span>',
|
||||
option: '<span class="option">{{ props.name }}</span>',
|
||||
'selected-option': '<span class="selected">{{ props.name }}</span>',
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
Select.vm.select({name: 'one'});
|
||||
Select.vm.select({ name: 'one' })
|
||||
|
||||
expect(spy).toHaveBeenCalledTimes(0);
|
||||
expect(Select.find('.selected').exists()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(spy).toHaveBeenCalledTimes(0)
|
||||
expect(Select.find('.selected').exists()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user