Skip to content

Commit

Permalink
chore(unit tests): Use side-effect import to fix TS errors (#9754)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Dec 26, 2023
1 parent 6a6687b commit 3b65087
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/forms/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testEnvironment: 'jest-environment-jsdom',
}
1 change: 1 addition & 0 deletions packages/forms/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom'
6 changes: 0 additions & 6 deletions packages/forms/src/__tests__/form.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import React from 'react'

import {
toHaveFocus,
toHaveClass,
toBeInTheDocument,
} from '@testing-library/jest-dom/matchers'
import {
screen,
render,
Expand All @@ -27,7 +22,6 @@ import {
FieldError,
Label,
} from '../index'
expect.extend({ toHaveFocus, toHaveClass, toBeInTheDocument })

describe('Form', () => {
const TestComponent = ({ onSubmit = () => {} }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/router/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
setupFilesAfterEnv: ['./jest.setup.js'],
setupFilesAfterEnv: ['./jest.setup.ts'],
testEnvironment: 'jest-environment-jsdom',
testMatch: ['**/*.test.+(ts|tsx|js|jsx)', '!**/__typetests__/*.ts'],
}
1 change: 0 additions & 1 deletion packages/router/jest.setup.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/router/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '@testing-library/jest-dom'

globalThis.scrollTo = jest.fn()
5 changes: 0 additions & 5 deletions packages/router/src/__tests__/links.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from 'react'

import { toHaveClass, toHaveStyle } from '@testing-library/jest-dom/matchers'
import { render } from '@testing-library/react'

// TODO: Remove when jest configs are in place
// @ts-expect-error - Issue with TS and jest-dom
expect.extend({ toHaveClass, toHaveStyle })

import { NavLink, useMatch, Link } from '../links'
import { LocationProvider } from '../location'
import { flattenSearchParams } from '../util'
Expand Down

0 comments on commit 3b65087

Please sign in to comment.