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