diff --git a/tests/unit/Ajax.spec.js b/tests/unit/Ajax.spec.js
index 4fa5e9a..d2d0ef5 100644
--- a/tests/unit/Ajax.spec.js
+++ b/tests/unit/Ajax.spec.js
@@ -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:
- // '
',
- // 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:
- // '
',
- // 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: '
',
- // 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:
- // '
',
- // 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:
- // '
',
- // 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:
- // '
',
- // 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:
- // '
',
- // 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);
+ });
});