Test mocking the bootstrap-vue tooltip directive with a no-op; this way we can still get other warnings.

This commit is contained in:
Dannon Baker
2020-12-17 12:47:09 -05:00
parent a8d195c2ea
commit fad0489e99
3 changed files with 32 additions and 16 deletions
@@ -1,10 +1,14 @@
import { mount } from "@vue/test-utils";
import { shallowMount } from "@vue/test-utils";
import DatasetName from "./DatasetName";
import { getLocalVue } from "jest/helpers";
const localVue = getLocalVue();
describe("Dataset Name", () => {
it("test dataset default", async () => {
const wrapper = mount(DatasetName, {
const wrapper = shallowMount(DatasetName, {
propsData: { item: { name: "name", state: "success" } },
localVue,
});
const state = wrapper.findAll(".name");
expect(state.length).toBe(1);
@@ -17,8 +21,9 @@ describe("Dataset Name", () => {
expect(Array.isArray(wrapper.emitted().copyDataset)).toBe(true);
});
it("test dataset error", async () => {
const wrapper = mount(DatasetName, {
const wrapper = shallowMount(DatasetName, {
propsData: { item: { name: "name", state: "error" } },
localVue,
});
const state = wrapper.findAll(".name");
expect(state.length).toBe(1);
@@ -28,8 +33,9 @@ describe("Dataset Name", () => {
expect(errorstate.at(0).classes()).toEqual(expect.arrayContaining(["text-danger"]));
});
it("test dataset paused", async () => {
const wrapper = mount(DatasetName, {
const wrapper = shallowMount(DatasetName, {
propsData: { item: { name: "name", state: "paused" } },
localVue,
});
const state = wrapper.findAll(".name");
expect(state.length).toBe(1);
+21 -7
View File
@@ -3,20 +3,24 @@
*/
import { timer } from "rxjs";
import { take } from "rxjs/operators";
import { shallowMount } from "@vue/test-utils";
import { createLocalVue, shallowMount } from "@vue/test-utils";
// Creates a watcher on the indicated vm/prop for use in testing
export function watchForChange({ vm, opts, propName, timeout = 1000, label = '' }) {
export function watchForChange({ vm, opts, propName, timeout = 1000, label = "" }) {
const start = new Date();
return new Promise((resolve, reject) => {
const timeoutID = setTimeout(() => {
reject(`${propName} never changed ${label}`);
}, timeout);
vm.$watch(propName, function (newVal, oldVal) {
clearTimeout(timeoutID);
const stop = new Date();
resolve({ timeElapsed: stop - start, newVal, oldVal });
}, opts);
vm.$watch(
propName,
function (newVal, oldVal) {
clearTimeout(timeoutID);
const stop = new Date();
resolve({ timeElapsed: stop - start, newVal, oldVal });
},
opts
);
});
}
@@ -49,6 +53,16 @@ export const showAll = (vm) => {
// usage: await wait(500);
export const wait = (n) => timer(n).pipe(take(1)).toPromise();
// Gets a localVue with custom directives
export function getLocalVue() {
const localVue = createLocalVue();
const mockedDirective = {
bind() {},
};
localVue.directive("b-tooltip", mockedDirective);
return localVue;
}
// Mounts a renderless component with sample content for testing
export function mountRenderless(component, localVue, propsData) {
return shallowMount(component, {
+1 -5
View File
@@ -2,8 +2,4 @@ import "@testing-library/jest-dom";
/* still don't understand what was invoking the following, but nothing should,
and this makes the tag tests work correctly */
global.XMLHttpRequest = undefined;
// stops Bootstrap's warnings when components can't find a non-existent doc
// https://github.com/bootstrap-vue/bootstrap-vue/issues/3303
process.env.BOOTSTRAP_VUE_NO_WARN = true;
global.XMLHttpRequest = undefined;