Skip to content

Commit 25a1d8f

Browse files
TASK: MD: Replace incorrect queryBy by getBy, add missing types in tests and replace .toBeNull() by not.toBeInTheDocument()
1 parent e8f3936 commit 25a1d8f

File tree

12 files changed

+25
-25
lines changed

12 files changed

+25
-25
lines changed

src/app/_components/eligibility/Eligibility.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("Eligibility", () => {
2020
}),
2121
);
2222

23-
const careCard: HTMLElement | null = screen.queryByTestId("non-urgent-care-card");
23+
const careCard: HTMLElement = screen.getByTestId("non-urgent-care-card");
2424
expect(careCard).toBeInTheDocument();
2525
});
2626

@@ -112,7 +112,7 @@ describe("Eligibility", () => {
112112

113113
it("should display EligibilityActions component", () => {
114114
render(Eligibility({ eligibilityContent: eligibilityContentBuilder().build() }));
115-
const actions = screen.getByText("Test Eligibility Actions Component");
115+
const actions: HTMLElement = screen.getByText("Test Eligibility Actions Component");
116116

117117
expect(actions).toBeVisible();
118118
});

src/app/_components/eligibility/EligibilityActions.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe("EligibilityActions", () => {
157157
}),
158158
);
159159

160-
const authButtonComponents = screen.getByTestId("action-auth-button-components");
160+
const authButtonComponents: HTMLElement = screen.getByTestId("action-auth-button-components");
161161

162162
const card = within(authButtonComponents).queryByTestId("action-auth-button-card");
163163

src/app/_components/feedback/FeedbackBanner.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("FeedbackBanner", () => {
77

88
render(<FeedbackBanner referrer={testReferrer} />);
99

10-
const feedbackText = screen.getByText(/This is a new NHS App service\. Help us improve it and/i);
10+
const feedbackText: HTMLElement = screen.getByText(/This is a new NHS App service\. Help us improve it and/i);
1111
const feedbackLink: HTMLAnchorElement = screen.getByRole("link", { name: "give your feedback" });
1212
const feedbackUrl: URL = new URL(feedbackLink.href);
1313

src/app/_components/nbs/NBSBookingAction.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("NBSBookingAction", () => {
2323
reduceBottomPadding={false}
2424
/>,
2525
);
26-
let bookingAction;
26+
let bookingAction: HTMLElement;
2727
if (renderAs === "anchor") {
2828
bookingAction = screen.getByRole("link", { name: displayText });
2929
} else {

src/app/_components/nbs/PharmacyBookingInfo.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("PharmacyBookingInfo", () => {
1313
it("should contain NBS booking with props to render as link, vaccine name and pharmacy booking text", () => {
1414
render(<PharmacyBookingInfo vaccineType={VaccineType.RSV} />);
1515

16-
const nbsBookingAction = screen.getByText("NBS Booking Link Test");
16+
const nbsBookingAction: HTMLElement = screen.getByText("NBS Booking Link Test");
1717

1818
expect(nbsBookingAction).toBeVisible();
1919
expect(NBSBookingActionForVaccine).toHaveBeenCalledWith(
@@ -30,7 +30,7 @@ describe("PharmacyBookingInfo", () => {
3030
it("should contain include correct text for older adults", () => {
3131
render(<PharmacyBookingInfo vaccineType={VaccineType.RSV} />);
3232

33-
const pharmacyBookingInfo: HTMLElement | null = screen.queryByText(
33+
const pharmacyBookingInfo: HTMLElement = screen.getByText(
3434
/This pharmacy service is only for adults aged 75 to 79./,
3535
);
3636

src/app/_components/nhs-app/BackToNHSAppLink.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("BackToNHSAppLink", () => {
3030

3131
it("clicking back link takes user to NHS app services page", async () => {
3232
render(<BackToNHSAppLink />);
33-
const backLink = screen.queryByRole("link", { name: "Back" });
33+
const backLink: HTMLElement = screen.getByRole("link", { name: "Back" });
3434
expect(backLink).toBeVisible();
3535
backLink?.click();
3636
expect(mockGoToPage).toHaveBeenCalledWith("services");
@@ -53,8 +53,8 @@ describe("BackToNHSAppLink", () => {
5353

5454
it("back link is not rendered", async () => {
5555
render(<BackToNHSAppLink />);
56-
const backLink = screen.queryByRole("link", { name: "Back" });
57-
expect(backLink).toBeNull();
56+
const backLink: HTMLElement | null = screen.queryByRole("link", { name: "Back" });
57+
expect(backLink).not.toBeInTheDocument();
5858
});
5959

6060
it("back action is not set", async () => {

src/app/_components/nhs-frontend/AppFooter.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ describe("AppFooter", () => {
77
});
88

99
it("renders crown copyright", async () => {
10-
const copyright = screen.queryByText(/© NHS England/);
10+
const copyright: HTMLElement = screen.getByText(/© NHS England/);
1111
expect(copyright).toBeVisible();
1212
});
1313

1414
it("renders privacy policy", async () => {
15-
const privacyPolicy = screen.queryByText(/Privacy policy/);
15+
const privacyPolicy: HTMLElement = screen.getByText(/Privacy policy/);
1616
expect(privacyPolicy).toBeVisible();
1717
});
1818

1919
it("renders help and support", async () => {
20-
const helpAndSupport = screen.queryByText(/Help and support/);
20+
const helpAndSupport: HTMLElement = screen.getByText(/Help and support/);
2121
expect(helpAndSupport).toBeVisible();
2222
});
2323

2424
it("renders accessibility statement", async () => {
25-
const accessibilityStatement = screen.queryByText(/Accessibility statement/);
25+
const accessibilityStatement: HTMLElement = screen.getByText(/Accessibility statement/);
2626
expect(accessibilityStatement).toBeVisible();
2727
});
2828

2929
it("renders cookies policy", async () => {
30-
const cookiesPolicy = screen.queryByText(/Cookies/);
30+
const cookiesPolicy: HTMLElement = screen.getByText(/Cookies/);
3131
expect(cookiesPolicy).toBeVisible();
3232
});
3333
});

src/app/_components/nhs-frontend/AppHeader.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const expectHeaderVisible = (expectedVisible: boolean) => {
2626
expect(serviceLink).toBeVisible();
2727
expect(logo).toBeVisible();
2828
} else {
29-
expect(serviceLink).toBeNull();
30-
expect(logo).toBeNull();
29+
expect(serviceLink).not.toBeInTheDocument();
30+
expect(logo).not.toBeInTheDocument();
3131
}
3232
};
3333

@@ -52,7 +52,7 @@ describe("AppHeader", () => {
5252
it("shows the app header with logout link", async () => {
5353
render(<AppHeader />);
5454
expectHeaderVisible(true);
55-
const logoutLink = screen.getByRole("link", { name: "Log out" });
55+
const logoutLink: HTMLElement = screen.getByRole("link", { name: "Log out" });
5656
expect(logoutLink).toBeVisible();
5757
expect(logoutLink?.getAttribute("href")).toEqual("#");
5858
});
@@ -83,8 +83,8 @@ describe("AppHeader", () => {
8383
mockSession = { status: "unauthenticated" };
8484
render(<AppHeader />);
8585
expectHeaderVisible(true);
86-
const logoutLink = screen.queryByRole("link", { name: "Log out" });
87-
expect(logoutLink).toBeNull();
86+
const logoutLink: HTMLElement | null = screen.queryByRole("link", { name: "Log out" });
87+
expect(logoutLink).not.toBeInTheDocument();
8888
});
8989

9090
it("should not include link destination for logo and service name", async () => {

src/app/_components/vaccine/Vaccine.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe("Any vaccine page", () => {
149149
it("should display custom RSV Pregnancy vaccine component with contentApi howToGet section", async () => {
150150
await renderNamedVaccinePage(VaccineType.RSV_PREGNANCY);
151151

152-
const rsvPregnancyInfo = screen.queryByTestId("rsv-pregnancy-mock");
152+
const rsvPregnancyInfo: HTMLElement = screen.getByTestId("rsv-pregnancy-mock");
153153

154154
expect(rsvPregnancyInfo).toBeInTheDocument();
155155
expect(RSVPregnancyInfo).toHaveBeenCalledWith(
@@ -164,7 +164,7 @@ describe("Any vaccine page", () => {
164164
it("should not display RSV Pregnancy component when vaccineType is not RSV_PREGNANCY", async () => {
165165
await renderNamedVaccinePage(VaccineType.TD_IPV_3_IN_1);
166166

167-
const rsvPregnancyInfo = screen.queryByTestId("rsv-pregnancy-mock");
167+
const rsvPregnancyInfo: HTMLElement | null = screen.queryByTestId("rsv-pregnancy-mock");
168168

169169
expect(rsvPregnancyInfo).not.toBeInTheDocument();
170170
expect(RSVPregnancyInfo).not.toHaveBeenCalled();

src/app/session-logout/page.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("SessionLogout", () => {
1919
</BrowserContextProvider>,
2020
);
2121
const loggedOutText = screen.queryByText("You have logged out");
22-
expect(loggedOutText).toBeNull();
22+
expect(loggedOutText).not.toBeInTheDocument();
2323
expect(mockGoToHomePage).toHaveBeenCalledTimes(1);
2424
});
2525

0 commit comments

Comments
 (0)