2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-22 10:30:34 +03:00

refactor ajax tests to use helpers

This commit is contained in:
Jeff
2018-08-12 12:33:30 -07:00
parent eed25d7a5a
commit 8e22400ce4
+11 -14
View File
@@ -1,9 +1,8 @@
import { shallowMount } from "@vue/test-utils"; import { selectWithProps } from "../helpers";
import VueSelect from "../../src/components/Select";
describe("Asynchronous Loading", () => { describe("Asynchronous Loading", () => {
it("can toggle the loading class", () => { it("can toggle the loading class", () => {
const Select = shallowMount(VueSelect); const Select = selectWithProps();
Select.vm.toggleLoading(); Select.vm.toggleLoading();
expect(Select.vm.mutableLoading).toEqual(true); expect(Select.vm.mutableLoading).toEqual(true);
@@ -15,7 +14,7 @@ describe("Asynchronous Loading", () => {
it("should trigger the onSearch callback when the search text changes", () => { it("should trigger the onSearch callback when the search text changes", () => {
const propsData = { onSearch: () => {} }; const propsData = { onSearch: () => {} };
const spy = jest.spyOn(propsData, "onSearch"); const spy = jest.spyOn(propsData, "onSearch");
const Select = shallowMount(VueSelect, { propsData }); const Select = selectWithProps(propsData);
Select.vm.search = "foo"; Select.vm.search = "foo";
@@ -30,7 +29,7 @@ describe("Asynchronous Loading", () => {
} }
}; };
const spy = jest.spyOn(propsData, "onSearch"); const spy = jest.spyOn(propsData, "onSearch");
const Select = shallowMount(VueSelect, { propsData }); const Select = selectWithProps(propsData);
Select.vm.search = "foo"; Select.vm.search = "foo";
Select.vm.search = ""; Select.vm.search = "";
@@ -40,7 +39,7 @@ describe("Asynchronous Loading", () => {
}); });
it("should trigger the search event when the search text changes", () => { it("should trigger the search event when the search text changes", () => {
const Select = shallowMount(VueSelect); const Select = selectWithProps();
Select.vm.search = "foo"; Select.vm.search = "foo";
@@ -51,7 +50,7 @@ describe("Asynchronous Loading", () => {
}); });
it("should not trigger the search event if the search text is empty", () => { it("should not trigger the search event if the search text is empty", () => {
const Select = shallowMount(VueSelect); const Select = selectWithProps();
Select.vm.search = "foo"; Select.vm.search = "foo";
Select.vm.search = ""; Select.vm.search = "";
@@ -63,8 +62,8 @@ describe("Asynchronous Loading", () => {
}); });
it("can set loading to false from the onSearch callback", () => { it("can set loading to false from the onSearch callback", () => {
const Select = shallowMount(VueSelect, { const Select = selectWithProps({
propsData: { onSearch: (search, loading) => loading(false) } onSearch: (search, loading) => loading(false)
}); });
Select.vm.search = "foo"; Select.vm.search = "foo";
@@ -73,8 +72,8 @@ describe("Asynchronous Loading", () => {
}); });
it("can set loading to true from the onSearch callback", () => { it("can set loading to true from the onSearch callback", () => {
const Select = shallowMount(VueSelect, { const Select = selectWithProps({
propsData: { onSearch: (search, loading) => loading(true) } onSearch: (search, loading) => loading(true)
}); });
Select.vm.search = "foo"; Select.vm.search = "foo";
@@ -83,9 +82,7 @@ describe("Asynchronous Loading", () => {
}); });
it("will sync mutable loading with the loading prop", () => { it("will sync mutable loading with the loading prop", () => {
const Select = shallowMount(VueSelect, { const Select = selectWithProps({ loading: false });
propsData: { loading: false }
});
Select.setProps({ loading: true }); Select.setProps({ loading: true });
expect(Select.vm.mutableLoading).toEqual(true); expect(Select.vm.mutableLoading).toEqual(true);
}); });