Skip to content

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

Replaced get* assertions in testing library with explicit assertions (#2428)

ZeroPlayerRodentaed19ae5396f
diff --git a/frontend/test/unit/specs/components/v-content-report-form.spec.js b/frontend/test/unit/specs/components/v-content-report-form.spec.js
index 2731b33f6..3505817d7 100644
--- a/frontend/test/unit/specs/components/v-content-report-form.spec.js
+++ b/frontend/test/unit/specs/components/v-content-report-form.spec.js
@@ -1,5 +1,3 @@
-/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["getByText", "getDmcaInput", "getMatureInput", "getOtherInput", "getCancelButton", "getReportButton", "getReportLink", "getDescriptionTextarea", "expect"] }] */
-
import { fireEvent, screen } from "@testing-library/vue"
import { render } from "~~/test/unit/test-utils/render"
@@ -15,34 +13,34 @@ jest.mock("~/composables/use-analytics", () => ({
}))
const getDmcaInput = () =>
- screen.getByRole("radio", {
+ screen.queryByRole("radio", {
name: /Infringes copyright/i,
})
const getMatureInput = () =>
- screen.getByRole("radio", {
+ screen.queryByRole("radio", {
name: /mature/i,
})
const getOtherInput = () =>
- screen.getByRole("radio", {
+ screen.queryByRole("radio", {
name: /other/i,
})
const getCancelButton = () =>
- screen.getByRole("button", {
+ screen.queryByRole("button", {
name: /cancel/i,
})
const getReportButton = () =>
- screen.getByRole("button", {
+ screen.queryByRole("button", {
name: /report/i,
})
// When DMCA selected
const getReportLink = () =>
- screen.getByRole("link", {
+ screen.queryByRole("link", {
name: /DMCA form/i,
})
// When other selected
const getDescriptionTextarea = () =>
- screen.getByRole("textbox", {
+ screen.queryByRole("textbox", {
name: /Describe the issue. Required/i,
})
@@ -76,50 +74,59 @@ describe("VContentReportForm", () => {
it("should contain the correct contents", async () => {
await render(VContentReportForm, options)
- getDmcaInput()
- getMatureInput()
- getOtherInput()
- getCancelButton()
- getReportLink()
+ expect(getDmcaInput()).toBeVisible()
+ expect(getMatureInput()).toBeVisible()
+ expect(getOtherInput()).toBeVisible()
+ expect(getCancelButton()).toBeVisible()
+ // By default, DMCA is selected, and we show a link to
+ // the report form instead of a report button.
+ expect(getReportButton()).not.toBeInTheDocument()
+ expect(getReportLink()).toBeVisible()
})
it("should render thank you note when report is sent", async () => {
- const { getByText } = render(VContentReportForm, options)
+ const { queryByText } = render(VContentReportForm, options)
await fireEvent.click(getMatureInput())
await fireEvent.click(getReportButton())
// Submission successful message
- getByText(/Thank you for reporting this content/i)
+ expect(
+ queryByText(/Thank you for reporting this content/i)
+ ).toBeInTheDocument()
})
it("should render error message if report sending fails", async () => {
ReportService.sendReport = () => Promise.reject()
- const { getByText } = render(VContentReportForm, options)
+ const { queryByText } = render(VContentReportForm, options)
await fireEvent.click(getMatureInput())
await fireEvent.click(getReportButton())
// Submission error message
- getByText(/Something went wrong, please try again after some time./i)
+ expect(
+ queryByText(/Something went wrong, please try again after some time./i)
+ ).toBeInTheDocument()
})
it("should render DMCA notice", async () => {
- const { getByText } = render(VContentReportForm, options)
+ const { queryByText } = render(VContentReportForm, options)
await fireEvent.click(getDmcaInput())
// Notice with link to provider
- getByText(
- /No action will be taken until this form is filled out and submitted/i
- )
+ expect(
+ queryByText(
+ /No action will be taken until this form is filled out and submitted/i
+ )
+ ).toBeInTheDocument()
getReportLink()
})
it("should render other description form", async () => {
- const { getByText } = render(VContentReportForm, options)
+ const { queryByText } = render(VContentReportForm, options)
await fireEvent.click(getOtherInput())
// Report form with a submit button
- getByText(/Describe the issue./i)
+ expect(queryByText(/Describe the issue./i)).toBeInTheDocument()
getDescriptionTextarea()
})