From fad0489e99178153dd95b741449f880dec7ad542 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 17 Dec 2020 12:47:09 -0500 Subject: [PATCH] Test mocking the bootstrap-vue tooltip directive with a no-op; this way we can still get other warnings. --- .../components/Dataset/DatasetName.test.js | 14 +++++++--- client/tests/jest/helpers.js | 28 ++++++++++++++----- client/tests/jest/jest.setup.js | 6 +--- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/client/src/components/Dataset/DatasetName.test.js b/client/src/components/Dataset/DatasetName.test.js index e42311d5206..0c6cc02968e 100644 --- a/client/src/components/Dataset/DatasetName.test.js +++ b/client/src/components/Dataset/DatasetName.test.js @@ -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); diff --git a/client/tests/jest/helpers.js b/client/tests/jest/helpers.js index 8a4006f95ff..1adfa7775be 100644 --- a/client/tests/jest/helpers.js +++ b/client/tests/jest/helpers.js @@ -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, { diff --git a/client/tests/jest/jest.setup.js b/client/tests/jest/jest.setup.js index e165b562fe6..660c40d654e 100644 --- a/client/tests/jest/jest.setup.js +++ b/client/tests/jest/jest.setup.js @@ -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; \ No newline at end of file