2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-19 09:50:33 +03:00

chore: yarn upgrade (#1062)

* chore: yarn upgrade

* upgrade vue test utils

* fix selectable suite

* fix slot suite

* fix ajax suite

* fix reactive options suite

* fix typeahead suite

* fix reduce tests

* fix tagging suite

* fix deselecting

* fix deselecting

* fix deselecting
This commit is contained in:
Jeff Sagal
2020-02-29 08:30:32 -08:00
committed by GitHub
parent ea8fdbf237
commit add1a5282b
11 changed files with 1187 additions and 1211 deletions
+1 -1
View File
@@ -35,7 +35,7 @@
"@babel/plugin-transform-runtime": "^7.4.0", "@babel/plugin-transform-runtime": "^7.4.0",
"@babel/preset-env": "^7.4.2", "@babel/preset-env": "^7.4.2",
"@babel/runtime": "^7.4.2", "@babel/runtime": "^7.4.2",
"@vue/test-utils": "^1.0.0-beta.29", "@vue/test-utils": "^1.0.0-beta.31",
"autoprefixer": "^9.4.7", "autoprefixer": "^9.4.7",
"babel-core": "^7.0.0-bridge.0", "babel-core": "^7.0.0-bridge.0",
"babel-loader": "^8.0.5", "babel-loader": "^8.0.5",
+10 -4
View File
@@ -13,10 +13,11 @@ describe("Asynchronous Loading", () => {
expect(Select.vm.mutableLoading).toEqual(true); expect(Select.vm.mutableLoading).toEqual(true);
}); });
it("should trigger the search event when the search text changes", () => { it("should trigger the search event when the search text changes", async () => {
const Select = selectWithProps(); const Select = selectWithProps();
Select.vm.search = "foo"; Select.vm.search = "foo";
await Select.vm.$nextTick();
const events = Select.emitted("search"); const events = Select.emitted("search");
@@ -24,11 +25,13 @@ describe("Asynchronous Loading", () => {
expect(events.length).toEqual(1); expect(events.length).toEqual(1);
}); });
it("should trigger the search event if the search text is empty", () => { it("should trigger the search event if the search text is empty", async () => {
const Select = selectWithProps(); const Select = selectWithProps();
Select.vm.search = "foo"; Select.vm.search = "foo";
await Select.vm.$nextTick();
Select.vm.search = ""; Select.vm.search = "";
await Select.vm.$nextTick();
const events = Select.emitted("search"); const events = Select.emitted("search");
@@ -36,7 +39,7 @@ describe("Asynchronous Loading", () => {
expect(events.length).toEqual(2); expect(events.length).toEqual(2);
}); });
it("can set loading to false from the @search event callback", () => { it("can set loading to false from the @search event callback", async () => {
const Select = shallowMount(vSelect, { const Select = shallowMount(vSelect, {
listeners: { listeners: {
search: (search, loading) => { search: (search, loading) => {
@@ -47,13 +50,16 @@ describe("Asynchronous Loading", () => {
Select.vm.mutableLoading = true; Select.vm.mutableLoading = true;
Select.vm.search = 'foo'; Select.vm.search = 'foo';
await Select.vm.$nextTick();
expect(Select.vm.mutableLoading).toEqual(false); expect(Select.vm.mutableLoading).toEqual(false);
}); });
it("will sync mutable loading with the loading prop", () => { it('will sync mutable loading with the loading prop', async () => {
const Select = selectWithProps({ loading: false }); const Select = selectWithProps({ loading: false });
Select.setProps({ loading: true }); Select.setProps({ loading: true });
await Select.vm.$nextTick();
expect(Select.vm.mutableLoading).toEqual(true); expect(Select.vm.mutableLoading).toEqual(true);
}); });
}); });
+2 -1
View File
@@ -1,9 +1,10 @@
import { selectWithProps } from "../helpers"; import { selectWithProps } from "../helpers";
describe("Removing values", () => { describe("Removing values", () => {
it("can remove the given tag when its close icon is clicked", () => { it("can remove the given tag when its close icon is clicked", async () => {
const Select = selectWithProps({ multiple: true }); const Select = selectWithProps({ multiple: true });
Select.vm.$data._value = 'one'; Select.vm.$data._value = 'one';
await Select.vm.$nextTick();
Select.find(".vs__deselect").trigger("click"); Select.find(".vs__deselect").trigger("click");
expect(Select.emitted().input).toEqual([[[]]]); expect(Select.emitted().input).toEqual([[[]]]);
+3 -1
View File
@@ -12,13 +12,15 @@ describe("Labels", () => {
expect(Select.find(".vs__selected").text()).toBe("Foo"); expect(Select.find(".vs__selected").text()).toBe("Foo");
}); });
it("will console.warn when options contain objects without a valid label key", () => { it("will console.warn when options contain objects without a valid label key", async () => {
const spy = jest.spyOn(console, "warn").mockImplementation(() => {}); const spy = jest.spyOn(console, "warn").mockImplementation(() => {});
const Select = selectWithProps({ const Select = selectWithProps({
options: [{}] options: [{}]
}); });
Select.vm.open = true; Select.vm.open = true;
await Select.vm.$nextTick();
expect(spy).toHaveBeenCalledWith( expect(spy).toHaveBeenCalledWith(
'[vue-select warn]: Label key "option.label" does not exist in options object {}.' + '[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"
+15 -4
View File
@@ -31,20 +31,21 @@ describe("Reset on options change", () => {
expect(spy.mock.calls[3][0]).toContain('Invalid prop: custom validator check failed for prop "resetOnOptionsChange"') expect(spy.mock.calls[3][0]).toContain('Invalid prop: custom validator check failed for prop "resetOnOptionsChange"')
}); });
it('should receive the new options, old options, and current value', () => { it('should receive the new options, old options, and current value', async () => {
let resetOnOptionsChange = jest.fn(option => option); let resetOnOptionsChange = jest.fn(option => option);
const Select = mountDefault( const Select = mountDefault(
{resetOnOptionsChange, options: ['bear'], value: 'selected'}, {resetOnOptionsChange, options: ['bear'], value: 'selected'},
); );
Select.setProps({options: ['lake', 'kite']}); Select.setProps({options: ['lake', 'kite']});
await Select.vm.$nextTick();
expect(resetOnOptionsChange).toHaveBeenCalledTimes(1); expect(resetOnOptionsChange).toHaveBeenCalledTimes(1);
expect(resetOnOptionsChange) expect(resetOnOptionsChange)
.toHaveBeenCalledWith(['lake', 'kite'], ['bear'], ['selected']); .toHaveBeenCalledWith(['lake', 'kite'], ['bear'], ['selected']);
}); });
it('should allow resetOnOptionsChange to be a function that returns true', () => { it('should allow resetOnOptionsChange to be a function that returns true', async () => {
let resetOnOptionsChange = () => true; let resetOnOptionsChange = () => true;
const Select = shallowMount(VueSelect, { const Select = shallowMount(VueSelect, {
propsData: {resetOnOptionsChange, options: ['one'], value: 'one'}, propsData: {resetOnOptionsChange, options: ['one'], value: 'one'},
@@ -52,6 +53,8 @@ describe("Reset on options change", () => {
const spy = jest.spyOn(Select.vm, 'clearSelection'); const spy = jest.spyOn(Select.vm, 'clearSelection');
Select.setProps({options: ['one', 'two']}); Select.setProps({options: ['one', 'two']});
await Select.vm.$nextTick();
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -74,14 +77,18 @@ describe("Reset on options change", () => {
const spy = jest.spyOn(Select.vm, 'clearSelection'); const spy = jest.spyOn(Select.vm, 'clearSelection');
Select.setProps({options: ['one', 'two']}); Select.setProps({options: ['one', 'two']});
await Select.vm.$nextTick();
expect(Select.vm.selectedValue).toEqual(['one']); expect(Select.vm.selectedValue).toEqual(['one']);
Select.setProps({options: ['two']}); Select.setProps({options: ['two']});
await Select.vm.$nextTick();
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
}); });
it("should reset the selected value when the options property changes", () => { it("should reset the selected value when the options property changes", async () => {
const Select = shallowMount(VueSelect, { const Select = shallowMount(VueSelect, {
propsData: { resetOnOptionsChange: true, options: ["one"] } propsData: { resetOnOptionsChange: true, options: ["one"] }
}); });
@@ -89,15 +96,19 @@ describe("Reset on options change", () => {
Select.vm.$data._value = 'one'; Select.vm.$data._value = 'one';
Select.setProps({options: ["four", "five", "six"]}); Select.setProps({options: ["four", "five", "six"]});
await Select.vm.$nextTick();
expect(Select.vm.selectedValue).toEqual([]); expect(Select.vm.selectedValue).toEqual([]);
}); });
it("should return correct selected value when the options property changes and a new option matches", () => { it("should return correct selected value when the options property changes and a new option matches", async () => {
const Select = shallowMount(VueSelect, { const Select = shallowMount(VueSelect, {
propsData: { value: "one", options: [], reduce(option) { return option.value } } propsData: { value: "one", options: [], reduce(option) { return option.value } }
}); });
Select.setProps({options: [{ label: "oneLabel", value: "one" }]}); Select.setProps({options: [{ label: "oneLabel", value: "one" }]});
await Select.vm.$nextTick();
expect(Select.vm.selectedValue).toEqual([{ label: "oneLabel", value: "one" }]); expect(Select.vm.selectedValue).toEqual([{ label: "oneLabel", value: "one" }]);
}); });
+2 -1
View File
@@ -211,7 +211,7 @@ describe("When reduce prop is defined", () => {
}); });
it("reacts correctly when value property changes", () => { it("reacts correctly when value property changes", async () => {
const optionToChangeTo = { id: 1, label: "Foo" }; const optionToChangeTo = { id: 1, label: "Foo" };
const Select = shallowMount(VueSelect, { const Select = shallowMount(VueSelect, {
propsData: { propsData: {
@@ -222,6 +222,7 @@ describe("When reduce prop is defined", () => {
}); });
Select.setProps({ value: optionToChangeTo.id }); Select.setProps({ value: optionToChangeTo.id });
await Select.vm.$nextTick();
expect(Select.vm.selectedValue).toEqual([optionToChangeTo]); expect(Select.vm.selectedValue).toEqual([optionToChangeTo]);
}); });
+8 -2
View File
@@ -1,27 +1,33 @@
import { selectWithProps } from "../helpers"; import { selectWithProps } from "../helpers";
describe("Selectable prop", () => { describe("Selectable prop", () => {
it("should select selectable option if clicked", () => { it("should select selectable option if clicked", async () => {
const Select = selectWithProps({ const Select = selectWithProps({
options: ["one", "two", "three"], options: ["one", "two", "three"],
selectable: (option) => option === "one" selectable: (option) => option === "one"
}); });
Select.vm.$data.open = true; Select.vm.$data.open = true;
await Select.vm.$nextTick();
Select.find(".vs__dropdown-menu li:first-child").trigger("mousedown"); Select.find(".vs__dropdown-menu li:first-child").trigger("mousedown");
await Select.vm.$nextTick();
expect(Select.vm.selectedValue).toEqual(["one"]); expect(Select.vm.selectedValue).toEqual(["one"]);
}) })
it("should not select not selectable option if clicked", () => { it("should not select not selectable option if clicked", async () => {
const Select = selectWithProps({ const Select = selectWithProps({
options: ["one", "two", "three"], options: ["one", "two", "three"],
selectable: (option) => option === "one" selectable: (option) => option === "one"
}); });
Select.vm.$data.open = true; Select.vm.$data.open = true;
await Select.vm.$nextTick();
Select.find(".vs__dropdown-menu li:last-child").trigger("mousedown"); Select.find(".vs__dropdown-menu li:last-child").trigger("mousedown");
await Select.vm.$nextTick();
expect(Select.vm.selectedValue).toEqual([]); expect(Select.vm.selectedValue).toEqual([]);
}); });
+2 -1
View File
@@ -42,7 +42,7 @@ describe('Scoped Slots', () => {
}); });
it('receives an option object to the option slot in the dropdown menu', it('receives an option object to the option slot in the dropdown menu',
() => { async () => {
const Select = mountDefault( const Select = mountDefault(
{value: 'one'}, {value: 'one'},
{ {
@@ -52,6 +52,7 @@ describe('Scoped Slots', () => {
}); });
Select.vm.open = true; Select.vm.open = true;
await Select.vm.$nextTick();
expect(Select.find({ref: 'dropdownMenu'}).text()).toEqual('onetwothree'); expect(Select.find({ref: 'dropdownMenu'}).text()).toEqual('onetwothree');
}); });
+4 -2
View File
@@ -153,7 +153,7 @@ describe("When Tagging Is Enabled", () => {
expect(Select.vm.selectedValue).toEqual([two]); expect(Select.vm.selectedValue).toEqual([two]);
}); });
it("should select an existing option if the search string matches an objects label from options", () => { it("should select an existing option if the search string matches an objects label from options", async () => {
let two = { label: "two" }; let two = { label: "two" };
const Select = selectWithProps({ const Select = selectWithProps({
taggable: true, taggable: true,
@@ -161,12 +161,13 @@ describe("When Tagging Is Enabled", () => {
}); });
Select.vm.search = "two"; Select.vm.search = "two";
await Select.vm.$nextTick();
searchSubmit(Select); searchSubmit(Select);
expect(Select.vm.selectedValue).toEqual([two]); expect(Select.vm.selectedValue).toEqual([two]);
}); });
it("should select an existing option if the search string matches an objects label from options when filter-options is false", () => { it("should select an existing option if the search string matches an objects label from options when filter-options is false", async () => {
let two = { label: "two" }; let two = { label: "two" };
const Select = selectWithProps({ const Select = selectWithProps({
taggable: true, taggable: true,
@@ -175,6 +176,7 @@ describe("When Tagging Is Enabled", () => {
}); });
Select.vm.search = "two"; Select.vm.search = "two";
await Select.vm.$nextTick();
searchSubmit(Select); searchSubmit(Select);
expect(Select.vm.selectedValue).toEqual([two]); expect(Select.vm.selectedValue).toEqual([two]);
+2 -1
View File
@@ -120,11 +120,12 @@ describe("Moving the Typeahead Pointer", () => {
}); });
describe("Measuring pixel distances", () => { describe("Measuring pixel distances", () => {
it("should calculate pointerHeight as the offsetHeight of the pointer element if it exists", () => { it("should calculate pointerHeight as the offsetHeight of the pointer element if it exists", async () => {
const Select = mountDefault(); const Select = mountDefault();
// Drop down must be open for $refs to exist // Drop down must be open for $refs to exist
Select.vm.open = true; Select.vm.open = true;
await Select.vm.$nextTick();
/** /**
* Since JSDom doesn't render layouts, set the offsetHeight explicitly * Since JSDom doesn't render layouts, set the offsetHeight explicitly
+1138 -1193
View File
File diff suppressed because it is too large Load Diff