Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HalvorHaugan committed Dec 23, 2024
1 parent e22616e commit 982a5a3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 309 deletions.
8 changes: 4 additions & 4 deletions @navikt/core/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,10 @@
"react-day-picker": "8.10.1"
},
"devDependencies": {
"@testing-library/dom": "9.3.4",
"@testing-library/jest-dom": "^5.16.0",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.2.0",
"@testing-library/dom": "10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
"@types/jscodeshift": "^0.11.11",
"concurrently": "9.0.1",
"fast-glob": "3.2.11",
Expand Down
7 changes: 2 additions & 5 deletions @navikt/core/react/src/date/datepicker/datepicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, render, screen } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { describe, test } from "vitest";
Expand All @@ -23,9 +23,6 @@ describe("Render datepicker", () => {
test("Should not crash when e.target is window", async () => {
render(<App />);

// eslint-disable-next-line testing-library/no-unnecessary-act -- https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning
await act(async () => {
await userEvent.click(screen.getByText("Velg dato"));
});
await userEvent.click(screen.getByText("Velg dato"));
});
});
15 changes: 5 additions & 10 deletions @navikt/core/react/src/date/hooks/useRangeDatepicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable testing-library/no-unnecessary-act -- https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning */
import { act, render, screen } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { describe, expect, test } from "vitest";
Expand Down Expand Up @@ -29,10 +28,8 @@ describe("Writing in input sets correct values", () => {

const fraInput = screen.getByRole("textbox", { name: "Fra" });
const tilInput = screen.getByRole("textbox", { name: "Til" });
await act(async () => {
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "03.08.2022");
});
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "03.08.2022");
const res = screen.getByTitle("res");
expect(res.innerHTML).toEqual(
JSON.stringify({
Expand All @@ -47,10 +44,8 @@ describe("Writing in input sets correct values", () => {

const fraInput = screen.getByRole("textbox", { name: "Fra" });
const tilInput = screen.getByRole("textbox", { name: "Til" });
await act(async () => {
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "02.08.2022");
});
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "02.08.2022");
const res = screen.getByTitle("res");
expect(res.innerHTML).toEqual(
JSON.stringify({
Expand Down
16 changes: 4 additions & 12 deletions @navikt/core/react/src/tabs/Tabs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, fireEvent, render, screen } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { describe, expect, test } from "vitest";
Expand Down Expand Up @@ -154,19 +154,11 @@ describe("Tabs", () => {
expect(screen.getByTestId("tab2")).toHaveFocus();

/* Move focus to tabPanel */
// eslint-disable-next-line testing-library/no-unnecessary-act
await act(async () => {
/* Tablist handles tabbing with setTimeout, so we need to use act */
await userEvent.tab();
});

await userEvent.tab();
expect(screen.getByTestId("tabpanel1")).toHaveFocus();
/* Move focus back to tablist, now tab1 should have focus */

// eslint-disable-next-line testing-library/no-unnecessary-act
await act(async () => {
await userEvent.tab({ shift: true });
});
/* Move focus back to tablist, now tab1 should have focus */
await userEvent.tab({ shift: true });
expect(screen.getByTestId("tab1")).toHaveFocus();
});
});
8 changes: 1 addition & 7 deletions @navikt/core/react/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
/**
* Setup-file is required to avoid "chai" type errors when using testing-library with vitest
*/
import matchers from "@testing-library/jest-dom/matchers";
import { expect } from "vitest";

expect.extend(matchers);
import "@testing-library/jest-dom/vitest";
3 changes: 2 additions & 1 deletion @navikt/core/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"noImplicitAny": false,
"resolveJsonModule": true
"resolveJsonModule": true,
"types": ["vitest/globals"]
}
}
Loading

0 comments on commit 982a5a3

Please sign in to comment.