2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-17 02:29:37 +03:00

WIP: v3 – remove onSearch callback prop (#811)

* remove onSearch callback prop

* update ajax docs

* docs formatting

* remove onSearch callback prop
This commit is contained in:
Jeff Sagal
2019-04-08 11:58:04 -07:00
committed by GitHub
parent b5e239c49c
commit 01ecee93d5
5 changed files with 66 additions and 100 deletions
+14 -44
View File
@@ -1,4 +1,6 @@
import { selectWithProps } from "../helpers";
import { shallowMount } from '@vue/test-utils';
import vSelect from '../../src/components/Select';
describe("Asynchronous Loading", () => {
it("can toggle the loading class", () => {
@@ -11,33 +13,6 @@ describe("Asynchronous Loading", () => {
expect(Select.vm.mutableLoading).toEqual(true);
});
it("should trigger the onSearch callback when the search text changes", () => {
const propsData = { onSearch: () => {} };
const spy = jest.spyOn(propsData, "onSearch");
const Select = selectWithProps(propsData);
Select.vm.search = "foo";
expect(spy).toHaveBeenCalled();
});
it("should not trigger the onSearch callback if the search text is empty", () => {
let calledWith = [];
const propsData = {
onSearch: search => {
calledWith.push(search);
}
};
const spy = jest.spyOn(propsData, "onSearch");
const Select = selectWithProps(propsData);
Select.vm.search = "foo";
Select.vm.search = "";
expect(spy).toHaveBeenCalledTimes(1);
expect(calledWith).toEqual(["foo"]);
});
it("should trigger the search event when the search text changes", () => {
const Select = selectWithProps();
@@ -49,7 +24,7 @@ describe("Asynchronous Loading", () => {
expect(events.length).toEqual(1);
});
it("should not trigger the search event if the search text is empty", () => {
it("should trigger the search event if the search text is empty", () => {
const Select = selectWithProps();
Select.vm.search = "foo";
@@ -57,30 +32,25 @@ describe("Asynchronous Loading", () => {
const events = Select.emitted("search");
expect(events).toContainEqual(["foo", Select.vm.toggleLoading]);
expect(events.length).toEqual(1);
expect(events).toContainEqual(["", Select.vm.toggleLoading]);
expect(events.length).toEqual(2);
});
it("can set loading to false from the onSearch callback", () => {
const Select = selectWithProps({
onSearch: (search, loading) => loading(false)
it("can set loading to false from the @search event callback", () => {
const Select = shallowMount(vSelect, {
listeners: {
search: (search, loading) => {
loading(false)
},
},
});
Select.vm.search = "foo";
Select.vm.mutableLoading = true;
Select.vm.search = 'foo';
expect(Select.vm.mutableLoading).toEqual(false);
});
it("can set loading to true from the onSearch callback", () => {
const Select = selectWithProps({
onSearch: (search, loading) => loading(true)
});
Select.vm.search = "foo";
expect(Select.vm.mutableLoading).toEqual(true);
});
it("will sync mutable loading with the loading prop", () => {
const Select = selectWithProps({ loading: false });
Select.setProps({ loading: true });