Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Use testing-library in test-utils/render (#2044)

Olga Bulat5ce77b21de24
diff --git a/.eslintrc.js b/.eslintrc.js
index 24bbed1e4..0fd6978ae 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -95,7 +95,16 @@ module.exports = {
message: "Use the <VLink> component instead of <RouterLink>.",
},
],
- "no-restricted-syntax": ["error", ...i18nDestructureRules],
+ "no-restricted-syntax": [
+ "error",
+ ...i18nDestructureRules,
+ {
+ selector:
+ "ImportDeclaration[source.value='@vue/test-utils']:has(ImportSpecifier[local.name='shallowMount'])",
+ message:
+ "Do not use @vue/test-utils' `shallowMount`. Use @testing-library/vue's `render` instead.",
+ },
+ ],
"unicorn/filename-case": ["error", { case: "kebabCase" }],
"@typescript-eslint/no-var-requires": ["off"],
"import/no-unresolved": [
diff --git a/frontend/package.json b/frontend/package.json
index 326d2f03d..e2c031b9e 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -150,6 +150,7 @@
"eslint-plugin-vue": "^9.9.0",
"eslint-plugin-vuejs-accessibility": "^1.1.1",
"jest": "^26.6.3",
+ "jest-fail-on-console": "^3.1.1",
"jest-transform-stub": "^2.0.0",
"module-alias": "^2.2.2",
"npm-run-all": "^4.1.5",
diff --git a/frontend/src/components/LoadingIcon.vue b/frontend/src/components/LoadingIcon.vue
index 480cd2e13..5bb4afdaf 100644
--- a/frontend/src/components/LoadingIcon.vue
+++ b/frontend/src/components/LoadingIcon.vue
@@ -1,5 +1,5 @@
<template>
- <div class="lds-ring">
+ <div class="lds-ring" data-testid="lds-ring">
<div />
<div />
<div />
diff --git a/frontend/src/components/VContentLink/VContentLink.vue b/frontend/src/components/VContentLink/VContentLink.vue
index 4c1565caf..f52e6d512 100644
--- a/frontend/src/components/VContentLink/VContentLink.vue
+++ b/frontend/src/components/VContentLink/VContentLink.vue
@@ -32,10 +32,11 @@ import type { SupportedMediaType } from "~/constants/media"
import { defineEvent } from "~/types/emits"
import VLink from "~/components/VLink.vue"
+import VIcon from "~/components/VIcon/VIcon.vue"
export default defineComponent({
name: "VContentLink",
- components: { VLink },
+ components: { VIcon, VLink },
props: {
/**
* One of the media types supported.
diff --git a/frontend/src/components/VFooter/VFooter.vue b/frontend/src/components/VFooter/VFooter.vue
index 59cd5589f..da24c0308 100644
--- a/frontend/src/components/VFooter/VFooter.vue
+++ b/frontend/src/components/VFooter/VFooter.vue
@@ -61,9 +61,10 @@ export default defineComponent({
},
props: {
/**
- * whether the footer is being rendered on a content page or an internal
- * page; This determines whether the Openverse logo and other links are
- * displayed.
+ * whether the footer is being rendered on a search page or an internal
+ * page (about, feedback, etc.); This determines whether the Openverse
+ * logo and other links are displayed.
+ * Search pages use "content" footer.
*/
mode: {
type: String as PropType<"internal" | "content">,
diff --git a/frontend/src/composables/use-focus-on-show.ts b/frontend/src/composables/use-focus-on-show.ts
index 6e28f4fa9..e8c66323a 100644
--- a/frontend/src/composables/use-focus-on-show.ts
+++ b/frontend/src/composables/use-focus-on-show.ts
@@ -1,4 +1,4 @@
-import { nextTick, watch, Ref } from "vue"
+import { nextTick, watch, Ref, computed, ref } from "vue"
import { tryOnScopeDispose, unrefElement } from "@vueuse/core"
@@ -38,13 +38,21 @@ export const useFocusOnShow = ({
/** */
}
let trap: UseFocusTrapReturn | undefined
+ const foundTabbableNode = ref<HTMLElement | null>(null)
+ const fallbackFocusNode = computed(
+ () => initialFocusElementRef.value || foundTabbableNode.value
+ )
if (trapFocusRef.value) {
trap = useFocusTrap(dialogRef, {
// Prevent FocusTrap from trying to focus the first element.
// We already do that in a more flexible, adaptive way in our Dialog composables.
initialFocus: false,
// if set to true, focus-trap prevents the default for the keyboard event, and we cannot handle it in our composables.
- escapeDeactivates: false,
+ escapeDeactivates: false, // Even though we pass `initialFocus` as `false` above, `focus-trap` still
+ // checks if the container has at least one tabbable element. Because it sometimes
+ // doesn't play nicely with Vue's rendering life-cycle, we need to get it a
+ // dynamic way to retrieve the fallback node.
+ fallbackFocus: () => fallbackFocusNode.value as HTMLElement,
})
activateFocusTrap = trap.activate
@@ -78,8 +86,10 @@ export const useFocusOnShow = ({
if (tabbable) {
ensureFocus(tabbable, { preventScroll: true, isActive })
+ foundTabbableNode.value = tabbable
} else {
ensureFocus(dialog, { preventScroll: true, isActive })
+ foundTabbableNode.value = dialog
if (dialog.tabIndex === undefined || dialog.tabIndex < 0) {
warn(noFocusableElementWarning)
}
diff --git a/frontend/src/layouts/content-layout.vue b/frontend/src/layouts/content-layout.vue
index a55e56156..d0de52baa 100644
--- a/frontend/src/layouts/content-layout.vue
+++ b/frontend/src/layouts/content-layout.vue
@@ -34,7 +34,7 @@
<div class="main-page flex h-full w-full min-w-0 flex-col justify-between">
<Nuxt />
<VFooter
- :mode="isSearchHeader ? 'content' : 'search'"
+ :mode="isSearchHeader ? 'content' : 'internal'"
class="border-t border-dark-charcoal-20 bg-white"
/>
</div>
@@ -132,7 +132,6 @@ export default defineComponent({
})
const showScrollButton = computed(() => scrollY.value > 70)
- provide("isHeaderScrolled", isHeaderScrolled)
provide("showScrollButton", showScrollButton)
provide(IsHeaderScrolledKey, isHeaderScrolled)
provide(IsSidebarVisibleKey, isSidebarVisible)
diff --git a/frontend/test/unit/fixtures/audio.js b/frontend/test/unit/fixtures/audio.js
index fa78ebfb9..753927987 100644
--- a/frontend/test/unit/fixtures/audio.js
+++ b/frontend/test/unit/fixtures/audio.js
@@ -1,7 +1,9 @@
+import * as uuid from "uuid"
+
export const getAudioObj = (overrides = {}) =>
Object.assign(
{
- id: "e19345b8-6937-49f7-a0fd-03bf057efc28",
+ id: uuid.v4(),
title: "La vie des bêtes",
foreign_landing_url: "https://www.jamendo.com/track/11188",
creator: "AS-POTIRONT!",
@@ -44,6 +46,7 @@ export const getAudioObj = (overrides = {}) =>
"http://localhost:8000/v1/audio/e19345b8-6937-49f7-a0fd-03bf057efc28",
related_url:
"http://localhost:8000/v1/audio/e19345b8-6937-49f7-a0fd-03bf057efc28/recommendations",
+ peaks: [],
},
overrides
)
diff --git a/frontend/test/unit/setup-after-env.js b/frontend/test/unit/setup-after-env.js
index 1aa0e99e9..ae4fba754 100644
--- a/frontend/test/unit/setup-after-env.js
+++ b/frontend/test/unit/setup-after-env.js
@@ -1,5 +1,8 @@
import Vue from "vue"
import "@testing-library/jest-dom"
+import failOnConsole from "jest-fail-on-console"
+
+failOnConsole()
Vue.prototype.$nuxt = {
context: {
@@ -8,5 +11,6 @@ Vue.prototype.$nuxt = {
captureEvent: jest.fn(),
},
localePath: (args) => args,
+ i18n: { t: (val) => val, tc: (val) => val },
},
}
diff --git a/frontend/test/unit/specs/components/AudioTrack/v-full-layout.spec.js b/frontend/test/unit/specs/components/AudioTrack/v-full-layout.spec.js
index d76f508e9..66c751b8a 100644
--- a/frontend/test/unit/specs/components/AudioTrack/v-full-layout.spec.js
+++ b/frontend/test/unit/specs/components/AudioTrack/v-full-layout.spec.js
@@ -1,8 +1,7 @@
-import { createLocalVue } from "@vue/test-utils"
-import { fireEvent, render, screen } from "@testing-library/vue"
+import { fireEvent, screen } from "@testing-library/vue"
import { getAudioObj } from "~~/test/unit/fixtures/audio"
-import { PiniaVuePlugin, createPinia } from "~~/test/unit/test-utils/pinia"
+import { render } from "~~/test/unit/test-utils/render"
import { useAnalytics } from "~/composables/use-analytics"
import { AUDIO } from "~/constants/media"
@@ -15,16 +14,11 @@ jest.mock("~/composables/use-analytics", () => ({
})),
}))
-const localVue = createLocalVue()
-localVue.use(PiniaVuePlugin)
-
describe("VFullLayout", () => {
it("should render the weblink button with the foreign landing url", () => {
const audio = getAudioObj()
render(VFullLayout, {
- localVue,
- pinia: createPinia(),
propsData: {
audio,
size: "s",
@@ -45,8 +39,6 @@ describe("VFullLayout", () => {
const audio = getAudioObj()
render(VFullLayout, {
- localVue,
- pinia: createPinia(),
propsData: {
audio,
size: "s",
diff --git a/frontend/test/unit/specs/components/ImageDetails/v-copy-license.spec.js b/frontend/test/unit/specs/components/ImageDetails/v-copy-license.spec.js
index b07c91447..9510f97d4 100644
--- a/frontend/test/unit/specs/components/ImageDetails/v-copy-license.spec.js
+++ b/frontend/test/unit/specs/components/ImageDetails/v-copy-license.spec.js
@@ -1,6 +1,8 @@
-import VCopyLicense from "~/components/VMediaInfo/VCopyLicense.vue"
+import { screen } from "@testing-library/vue"
+
+import { render } from "~~/test/unit/test-utils/render"
-import render from "../../../test-utils/render"
+import VCopyLicense from "~/components/VMediaInfo/VCopyLicense.vue"
describe("VCopyLicense", () => {
let options = null
@@ -20,6 +22,7 @@ describe("VCopyLicense", () => {
license_url: "http://license.com",
creator: "John",
creator_url: "http://creator.com",
+ frontendMediaType: "image",
},
fullLicenseName: "LICENSE",
}
@@ -29,7 +32,9 @@ describe("VCopyLicense", () => {
})
it("should contain the correct contents", () => {
- const wrapper = render(VCopyLicense, options)
- expect(wrapper.find(".copy-license")).toBeDefined()
+ render(VCopyLicense, options)
+ expect(
+ screen.queryAllByText("media-details.reuse.copy-license.copy-text")
+ ).toHaveLength(3)
})
})
diff --git a/frontend/test/unit/specs/components/VMediaTag/v-media-tag.spec.js b/frontend/test/unit/specs/components/VMediaTag/v-media-tag.spec.js
index 3b03774b8..966ee8438 100644
--- a/frontend/test/unit/specs/components/VMediaTag/v-media-tag.spec.js
+++ b/frontend/test/unit/specs/components/VMediaTag/v-media-tag.spec.js
@@ -1,6 +1,7 @@
import { RouterLinkStub } from "@vue/test-utils"
+import { screen } from "@testing-library/vue"
-import render from "~/../test/unit/test-utils/render"
+import { render } from "~~/test/unit/test-utils/render"
import VMediaTag from "~/components/VMediaTag/VMediaTag.vue"
@@ -14,9 +15,8 @@ describe("VMediaTag", () => {
})
it("should render an span tag by default", () => {
- const wrapper = render(VMediaTag, options)
- expect(wrapper.vm.$props.tag).toEqual("span")
- expect(wrapper.vm.$el).toBeInstanceOf(HTMLSpanElement)
+ const { container } = render(VMediaTag, options)
+ expect(container.firstChild.tagName).toEqual("SPAN")
})
it("should render the supplied tag", () => {
@@ -26,10 +26,9 @@ describe("VMediaTag", () => {
href: "https://example.com/",
}
- const wrapper = render(VMediaTag, options)
- expect(wrapper.vm.$props.tag).toEqual("a")
- expect(wrapper.vm.$el).toBeInstanceOf(HTMLAnchorElement)
- expect(wrapper.vm.$el.href).toEqual("https://example.com/")
+ const { container } = render(VMediaTag, options)
+ expect(container.firstChild.tagName).toEqual("A")
+ expect(container.firstChild.href).toEqual("https://example.com/")
})
it("should render the supplied Vue component", () => {
@@ -42,19 +41,17 @@ describe("VMediaTag", () => {
RouterLink: RouterLinkStub,
}
- const wrapper = render(VMediaTag, options)
- expect(wrapper.vm.$props.tag).toEqual("RouterLink")
- expect(wrapper.vm.$el).toBeInstanceOf(HTMLAnchorElement)
+ const { container } = render(VMediaTag, options)
+ expect(container.firstChild.tagName).toEqual("A")
})
it("renders slot content", () => {
+ const label = "I'm a label"
options.slots = {
- default: '<div id="slot-content">Hello</div>',
+ default: `<div aria-label="${label}">Hello</div>`,
}
- const wrapper = render(VMediaTag, options)
- const element = wrapper.find("#slot-content").element
- expect(element).toBeInstanceOf(HTMLDivElement)
- expect(element.textContent).toEqual("Hello")
+ render(VMediaTag, options)
+ expect(screen.queryByLabelText(label)).toBeDefined()
})
})
diff --git a/frontend/test/unit/specs/components/loading-icon.spec.js b/frontend/test/unit/specs/components/loading-icon.spec.js
index cfcc7a8ad..d62b5c577 100644
--- a/frontend/test/unit/specs/components/loading-icon.spec.js
+++ b/frontend/test/unit/specs/components/loading-icon.spec.js
@@ -1,10 +1,12 @@
-import LoadingIcon from "~/components/LoadingIcon.vue"
+import { screen } from "@testing-library/vue"
+
+import { render } from "~~/test/unit/test-utils/render"
-import render from "../../test-utils/render"
+import LoadingIcon from "~/components/LoadingIcon.vue"
describe("LoadingIcon", () => {
it("should render correct contents", () => {
- const wrapper = render(LoadingIcon)
- expect(wrapper.find(".lds-ring").vm).toBeDefined()
+ render(LoadingIcon)
+ expect(screen.getByTestId("lds-ring")).toBeDefined()
})
})
diff --git a/frontend/test/unit/specs/components/related-audios.spec.js b/frontend/test/unit/specs/components/related-audios.spec.js
deleted file mode 100644
index 53c8f251d..000000000
--- a/frontend/test/unit/specs/components/related-audios.spec.js
+++ /dev/null
@@ -1,47 +0,0 @@
-import { createLocalVue, mount } from "@vue/test-utils"
-import VueI18n from "vue-i18n"
-
-import { PiniaVuePlugin, createPinia } from "~~/test/unit/test-utils/pinia"
-
-import VRelatedAudio from "~/components/VAudioDetails/VRelatedAudio.vue"
-
-import render from "../../test-utils/render"
-
-const audioResults = [{ id: "audio1" }, { id: "audio2" }]
-
-const localVue = createLocalVue()
-localVue.use(VueI18n)
-localVue.prototype.$nuxt = {
- nbFetching: 0,
-}
-localVue.use(PiniaVuePlugin)
-
-const doRender = async () => {
- const pinia = createPinia()
-
- return render(
- VRelatedAudio,
- {
- localVue,
- pinia,
- propsData: {
- media: audioResults,
- fetchState: { isFetching: false, isError: false },
- },
- stubs: { LoadingIcon: true, VAudioTrack: true },
- },
- mount
- )
-}
-
-describe("RelatedAudios", () => {
- it("should render content when finished loading related audios", async () => {
- const wrapper = await doRender()
-
- const header = wrapper.find("h2").text()
- expect(header).toEqual("audio-details.related-audios")
-
- const audioTracks = wrapper.findAll("vaudiotrack-stub")
- expect(audioTracks.length).toEqual(audioResults.length)
- })
-})
diff --git a/frontend/test/unit/specs/components/image-grid.spec.js b/frontend/test/unit/specs/components/v-image-grid.spec.js
similarity index 62%
rename from frontend/test/unit/specs/components/image-grid.spec.js
rename to frontend/test/unit/specs/components/v-image-grid.spec.js
index 77f66ecad..e25f8ca27 100644
--- a/frontend/test/unit/specs/components/image-grid.spec.js
+++ b/frontend/test/unit/specs/components/v-image-grid.spec.js
@@ -1,20 +1,9 @@
-import { render, screen } from "@testing-library/vue"
-import VueI18n from "vue-i18n"
+import { screen } from "@testing-library/vue"
-import { createLocalVue } from "@vue/test-utils"
-
-import { PiniaVuePlugin, createPinia } from "~~/test/unit/test-utils/pinia"
-
-import messages from "~/locales/en.json"
+import { render } from "~~/test/unit/test-utils/render"
import VImageGrid from "~/components/VSearchResultsGrid/VImageGrid.vue"
-const i18n = new VueI18n({
- locale: "en",
- fallbackLocale: "en",
- messages: { en: messages },
-})
-
const propsData = {
images: [
{ id: "i1", url: "http://localhost:8080/i1.png", title: "image1" },
@@ -29,19 +18,11 @@ const propsData = {
}
describe("VImageGrid", () => {
- let localVue
- let pinia
let options
beforeEach(() => {
- localVue = createLocalVue()
- localVue.use(PiniaVuePlugin)
- pinia = createPinia()
options = {
- localVue,
- pinia,
props: propsData,
stubs: ["VLicense"],
- mocks: { $nuxt: { context: { i18n } } },
}
})
it("renders images without load more button", () => {
diff --git a/frontend/test/unit/specs/components/v-related-audios.spec.js b/frontend/test/unit/specs/components/v-related-audios.spec.js
new file mode 100644
index 000000000..3737f34e7
--- /dev/null
+++ b/frontend/test/unit/specs/components/v-related-audios.spec.js
@@ -0,0 +1,30 @@
+import { screen } from "@testing-library/vue"
+
+import { render } from "~~/test/unit/test-utils/render"
+import { getAudioObj } from "~~/test/unit/fixtures/audio"
+
+import VRelatedAudio from "~/components/VAudioDetails/VRelatedAudio.vue"
+
+const audioResults = [getAudioObj(), getAudioObj()]
+
+describe("RelatedAudios", () => {
+ it("should render content when finished loading related audios", async () => {
+ await render(VRelatedAudio, {
+ propsData: {
+ media: audioResults,
+ fetchState: { isFetching: false, isError: false },
+ },
+ stubs: { LoadingIcon: true, VAudioThumbnail: true },
+ })
+
+ expect(screen.findByText("audio-details.related-audios"))
+
+ expect(screen.queryAllByLabelText("play-pause.play")).toHaveLength(
+ // Two for each as the "row" layout rendered by VRelatedAudio
+ // renders a "large" and "small" version that are visually hidden by a parent
+ // depending on the breakpoint (but critically still rendered in the
+ // DOM)
+ audioResults.length * 2
+ )
+ })
+})
diff --git a/frontend/test/unit/specs/components/related-images.spec.js b/frontend/test/unit/specs/components/v-related-images.spec.js
similarity index 66%
rename from frontend/test/unit/specs/components/related-images.spec.js
rename to frontend/test/unit/specs/components/v-related-images.spec.js
index 8a11d5e38..1a5f58e86 100644
--- a/frontend/test/unit/specs/components/related-images.spec.js
+++ b/frontend/test/unit/specs/components/v-related-images.spec.js
@@ -1,10 +1,6 @@
-import VueI18n from "vue-i18n"
-import { createLocalVue } from "@vue/test-utils"
-import { render, screen } from "@testing-library/vue"
+import { screen } from "@testing-library/vue"
-import { PiniaVuePlugin, createPinia } from "~~/test/unit/test-utils/pinia"
-
-import messages from "~/locales/en.json"
+import { render } from "~~/test/unit/test-utils/render"
import VRelatedImages from "~/components/VImageDetails/VRelatedImages.vue"
@@ -12,27 +8,15 @@ const media = [
{ id: "img1", url: "https://wp.org/img1.jpg" },
{ id: "img2", url: "https://wp.org/img2.jpg" },
]
-const i18n = new VueI18n({
- locale: "en",
- fallbackLocale: "en",
- messages: { en: messages },
-})
-const localVue = createLocalVue()
-localVue.use(VueI18n)
-localVue.use(PiniaVuePlugin)
+
describe("RelatedImage", () => {
let props
let options
- let pinia
beforeEach(() => {
- pinia = createPinia()
props = { media, fetchState: { isFetching: false } }
options = {
- localVue,
- pinia,
propsData: props,
stubs: ["VLicense"],
- mocks: { $nuxt: { context: { i18n } } },
}
})
it("should render an image grid", () => {
diff --git a/frontend/test/unit/specs/pages/browse-page.spec.js b/frontend/test/unit/specs/pages/browse-page.spec.js
index e692617be..3ab2f217c 100644
--- a/frontend/test/unit/specs/pages/browse-page.spec.js
+++ b/frontend/test/unit/specs/pages/browse-page.spec.js
@@ -1,30 +1,27 @@
-import { render, screen } from "@testing-library/vue"
-import { createLocalVue } from "@vue/test-utils"
+import { screen } from "@testing-library/vue"
import { ref } from "vue"
-import { createPinia, PiniaVuePlugin } from "~~/test/unit/test-utils/pinia"
+import { render } from "~~/test/unit/test-utils/render"
-import SearchIndex from "~/pages/search.vue"
import { IMAGE } from "~/constants/media"
-
import { useSearchStore } from "~/stores/search"
+import SearchIndex from "~/pages/search.vue"
+
+import { IsHeaderScrolledKey, IsSidebarVisibleKey } from "~/types/provides"
+
describe("SearchIndex", () => {
let options
- let localVue
- let pinia
+ const defaultProvideOptions = {
+ showScrollButton: ref(false),
+ [IsHeaderScrolledKey]: ref(false),
+ [IsSidebarVisibleKey]: ref(false),
+ }
let searchStore
beforeEach(() => {
- localVue = createLocalVue()
- localVue.use(PiniaVuePlugin)
- pinia = createPinia()
- searchStore = useSearchStore(pinia)
- searchStore.setSearchTerm("cat")
- searchStore.setSearchType(IMAGE)
options = {
- localVue,
- pinia,
+ provide: defaultProvideOptions,
mocks: {
$router: { path: { name: "search-image" } },
$route: { path: "/search/image" },
@@ -38,17 +35,24 @@ describe("SearchIndex", () => {
})
it("hides the scroll button when injected value is false", () => {
- options.provide = { showScrollButton: ref(false) }
+ options.provide.showScrollButton.value = false
- render(SearchIndex, options)
+ render(SearchIndex, options, (localVue, options) => {
+ searchStore = useSearchStore(options.pinia)
+ searchStore.setSearchTerm("cat")
+ searchStore.setSearchType(IMAGE)
+ })
expect(screen.queryByLabelText(/scroll/i)).not.toBeVisible()
})
- it("shows the scroll button when injected value is false", () => {
- options.provide = { showScrollButton: ref(true) }
-
- render(SearchIndex, options)
+ it("shows the scroll button when injected value is true", () => {
+ options.provide.showScrollButton.value = true
+ render(SearchIndex, options, (localVue, options) => {
+ searchStore = useSearchStore(options.pinia)
+ searchStore.setSearchTerm("cat")
+ searchStore.setSearchType(IMAGE)
+ })
expect(screen.queryByLabelText(/scroll/i)).toBeVisible()
})
diff --git a/frontend/test/unit/test-utils/render.js b/frontend/test/unit/test-utils/render.js
index f082ddb07..58f0bc23a 100644
--- a/frontend/test/unit/test-utils/render.js
+++ b/frontend/test/unit/test-utils/render.js
@@ -1,26 +1,35 @@
import VueI18n from "vue-i18n"
-import { shallowMount, createLocalVue } from "@vue/test-utils"
-const localVue = createLocalVue()
-localVue.use(VueI18n)
+import { render as testingLibraryRender } from "@testing-library/vue"
-const messages = require("../../../src/locales/en.json")
+import { createPinia, PiniaVuePlugin } from "~~/test/unit/test-utils/pinia"
+
+import messages from "~/locales/en.json"
const i18n = new VueI18n({
locale: "en",
fallbackLocale: "en",
- messages,
+ messages: { en: messages },
+ missingWarn: false,
+ silentTranslationWarn: true,
})
-const render = (
- Component,
- options = { localVue, i18n },
- renderer = shallowMount
-) => {
- if (!options.i18n) {
+export const render = (Component, options = {}, configureCb = null) => {
+ if (!options?.i18n) {
options.i18n = i18n
}
- return renderer(Component, options)
+ if (!options?.pinia) {
+ options.pinia = createPinia()
+ }
+
+ return testingLibraryRender(Component, options, (localVue) => {
+ localVue.use(VueI18n)
+ localVue.use(PiniaVuePlugin)
+
+ if (configureCb) {
+ configureCb(localVue, options)
+ }
+ })
}
export default render
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a611ddc4a..54bb132e6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -97,6 +97,7 @@ importers:
focus-visible: ^5.2.0
glob: ^8.0.1
jest: ^26.6.3
+ jest-fail-on-console: ^3.1.1
jest-transform-stub: ^2.0.0
module-alias: ^2.2.2
node-html-parser: ^5.3.3
@@ -222,6 +223,7 @@ importers:
eslint-plugin-vue: [email protected]
eslint-plugin-vuejs-accessibility: [email protected]
+ jest-fail-on-console: 3.1.1
jest-transform-stub: 2.0.0
module-alias: 2.2.2
npm-run-all: 4.1.5
@@ -12909,6 +12911,12 @@ packages:
jest-util: 26.6.2
dev: true
+ /jest-fail-on-console/3.1.1:
+ resolution: {integrity: sha512-g9HGhKcWOz8lHeZhLCXGg+RD/7upngiKkkBrHimsO/tGB0qi++QZffOgybjeI2bDW1qgdFiJJEG6t/WeTlfmOw==}
+ dependencies:
+ chalk: 4.1.2
+ dev: true
+
/jest-get-type/26.3.0:
resolution: {integrity: sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==}
engines: {node: '>= 10.14.2'}