mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-16 09:10:33 +03:00
Complete AJAX specs
This commit is contained in:
+78
-140
@@ -11,144 +11,82 @@ describe("Asynchronous Loading", () => {
|
||||
Select.vm.toggleLoading(true);
|
||||
expect(Select.vm.mutableLoading).toEqual(true);
|
||||
});
|
||||
//
|
||||
// it("should trigger the onSearch callback when the search text changes", done => {
|
||||
// const vm = new Vue({
|
||||
// template:
|
||||
// '<div><v-select ref="select" :on-search="foo"></v-select></div>',
|
||||
// data: {
|
||||
// called: false
|
||||
// },
|
||||
// methods: {
|
||||
// foo(val) {
|
||||
// this.called = val;
|
||||
// }
|
||||
// }
|
||||
// }).$mount();
|
||||
//
|
||||
// vm.$refs.select.search = "foo";
|
||||
//
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.called).toEqual("foo");
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// it("should not trigger the onSearch callback if the search text is empty", done => {
|
||||
// const vm = new Vue({
|
||||
// template:
|
||||
// '<div><v-select ref="select" search="foo" :on-search="foo"></v-select></div>',
|
||||
// data: { called: false },
|
||||
// methods: {
|
||||
// foo(val) {
|
||||
// this.called = !this.called;
|
||||
// }
|
||||
// }
|
||||
// }).$mount();
|
||||
//
|
||||
// vm.$refs.select.search = "foo";
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.called).toBe(true);
|
||||
// vm.$refs.select.search = "";
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.called).toBe(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// it("should trigger the search event when the search text changes", done => {
|
||||
// const vm = new Vue({
|
||||
// template: '<div><v-select ref="select" @search="foo"></v-select></div>',
|
||||
// data: {
|
||||
// called: false
|
||||
// },
|
||||
// methods: {
|
||||
// foo(val) {
|
||||
// this.called = val;
|
||||
// }
|
||||
// }
|
||||
// }).$mount();
|
||||
//
|
||||
// vm.$refs.select.search = "foo";
|
||||
//
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.called).toEqual("foo");
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// it("should not trigger the search event if the search text is empty", done => {
|
||||
// const vm = new Vue({
|
||||
// template:
|
||||
// '<div><v-select ref="select" search="foo" @search="foo"></v-select></div>',
|
||||
// data: { called: false },
|
||||
// methods: {
|
||||
// foo(val) {
|
||||
// this.called = !this.called;
|
||||
// }
|
||||
// }
|
||||
// }).$mount();
|
||||
//
|
||||
// vm.$refs.select.search = "foo";
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.called).toBe(true);
|
||||
// vm.$refs.select.search = "";
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.called).toBe(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// it("can set loading to false from the onSearch callback", done => {
|
||||
// const vm = new Vue({
|
||||
// template:
|
||||
// '<div><v-select loading ref="select" :on-search="foo"></v-select></div>',
|
||||
// methods: {
|
||||
// foo(search, loading) {
|
||||
// loading(false);
|
||||
// }
|
||||
// }
|
||||
// }).$mount();
|
||||
//
|
||||
// vm.$refs.select.search = "foo";
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.$refs.select.mutableLoading).toEqual(false);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// it("can set loading to true from the onSearch callback", done => {
|
||||
// const vm = new Vue({
|
||||
// template:
|
||||
// '<div><v-select loading ref="select" :on-search="foo"></v-select></div>',
|
||||
// methods: {
|
||||
// foo(search, loading) {
|
||||
// loading(true);
|
||||
// }
|
||||
// }
|
||||
// }).$mount();
|
||||
//
|
||||
// let select = vm.$refs.select;
|
||||
// select.onSearch(select.search, select.toggleLoading);
|
||||
//
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.$refs.select.mutableLoading).toEqual(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// it("will sync mutable loading with the loading prop", done => {
|
||||
// const vm = new Vue({
|
||||
// template:
|
||||
// '<div><v-select ref="select" :loading="loading"></v-select></div>',
|
||||
// data: { loading: false }
|
||||
// }).$mount();
|
||||
// vm.loading = true;
|
||||
// Vue.nextTick(() => {
|
||||
// expect(vm.$refs.select.mutableLoading).toEqual(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
it("should trigger the onSearch callback when the search text changes", () => {
|
||||
const propsData = { onSearch: () => {} };
|
||||
const spy = jest.spyOn(propsData, "onSearch");
|
||||
const Select = shallowMount(VueSelect, { 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 = shallowMount(VueSelect, { 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 = shallowMount(VueSelect);
|
||||
|
||||
Select.vm.search = "foo";
|
||||
|
||||
const events = Select.emitted("search");
|
||||
|
||||
expect(events).toContainEqual(["foo", Select.vm.toggleLoading]);
|
||||
expect(events.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("should not trigger the search event if the search text is empty", () => {
|
||||
const Select = shallowMount(VueSelect);
|
||||
|
||||
Select.vm.search = "foo";
|
||||
Select.vm.search = "";
|
||||
|
||||
const events = Select.emitted("search");
|
||||
|
||||
expect(events).toContainEqual(["foo", Select.vm.toggleLoading]);
|
||||
expect(events.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("can set loading to false from the onSearch callback", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { onSearch: (search, loading) => loading(false) }
|
||||
});
|
||||
|
||||
Select.vm.search = "foo";
|
||||
|
||||
expect(Select.vm.mutableLoading).toEqual(false);
|
||||
});
|
||||
|
||||
it("can set loading to true from the onSearch callback", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { 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 = shallowMount(VueSelect, {
|
||||
propsData: { loading: false }
|
||||
});
|
||||
Select.setProps({ loading: true });
|
||||
expect(Select.vm.mutableLoading).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user