Skip to content

Commit

Permalink
fix(jest): fix jest config and removing faulty useless server wrapper (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdebon committed Dec 12, 2022
1 parent b879919 commit ddb40e1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 31 deletions.
22 changes: 1 addition & 21 deletions __tests__/utils/setup-jest.tsx
@@ -1,28 +1,8 @@
import '@testing-library/jest-dom'
import { RenderOptions, cleanup, render } from '@testing-library/react'
import { RenderOptions, render } from '@testing-library/react'
import React from 'react'
import { server } from '../server'
import { Props, Wrapper } from './providers'

beforeAll(() =>
server.listen({
onUnhandledRequest: ({ method, url }) => {
if (url.pathname.indexOf('__test') === -1) {
throw new Error(`Unhandled ${method} request to ${url}`)
}
},
})
)

afterEach(() => {
server.resetHandlers()
cleanup()
})

afterAll(() => {
server.close()
})

type CustomRenderOptions = {
wrapperProps?: Props
} & Omit<RenderOptions, 'wrapper'>
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
@@ -1,4 +1,4 @@
const { getJestProjects } = require('@nrwl/jest')
import { getJestProjects } from '@nrwl/jest'

export default {
projects: getJestProjects(),
Expand Down
2 changes: 1 addition & 1 deletion jest.preset.js
Expand Up @@ -7,7 +7,7 @@ module.exports = {
testPathIgnorePatterns: ['./node_modules/', './.next/', './__tests__/utils/setup-jest.tsx'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': 'babel-jest',
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': ['babel-jest', { presets: ['@nrwl/react/babel'] }],
'^.+\\.scss$': 'jest-scss-transform',
},
transformIgnorePatterns: [
Expand Down
Expand Up @@ -27,7 +27,7 @@ const WrapperForm = ({ children }) => {
value: 'asdas',
isSecret: false,
},
mode: 'onChange',
mode: 'all',
})

return <FormProvider {...methods}>{children}</FormProvider>
Expand Down Expand Up @@ -73,8 +73,10 @@ describe('CrudEnvironmentVariableModal', () => {
fireEvent.change(textarea, { target: { value: '' } })
})

const error = screen.getByText('Please enter a value.')
expect(error).toBeTruthy()
await waitFor(async () => {
const error = screen.getByText('Please enter a value.')
expect(error).toBeTruthy()
})

await waitFor(async () => {
const button = await getByRole(baseElement, 'button', { name: 'Confirm' })
Expand Down
Expand Up @@ -95,8 +95,10 @@ describe('ImportEnvironmentVariableModal', () => {
fireEvent.input(input, { target: { value: '' } })
})

const warningIcon = screen.getByTestId('warning-icon-left')
expect(warningIcon).toBeInTheDocument()
await waitFor(() => {
const warningIcon = screen.getByTestId('warning-icon-left')
expect(warningIcon).toBeInTheDocument()
})

await waitFor(async () => {
const button = await getByTestId(baseElement, 'submit-button')
Expand Down
Expand Up @@ -60,6 +60,7 @@ describe('PageSettingsAdvanced', () => {

await act(() => {
const input = getByLabelText('build.timeout_max_sec')
fireEvent.input(input, { target: { value: '79' } })
fireEvent.input(input, { target: { value: '' } })
})

Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -49,6 +49,7 @@
"date-fns": "^2.29.3",
"date-fns-tz": "^1.3.7",
"fast-deep-equal": "^3.1.3",
"history": "^5.2.0",
"logrocket": "^3.0.1",
"msw": "^0.42.1",
"postcss": "8.4.16",
Expand All @@ -67,8 +68,7 @@
"react-use-websocket": "^4.2.0",
"regenerator-runtime": "0.13.7",
"tailwindcss": "3.1.8",
"tslib": "^2.3.0",
"history": "^5.2.0"
"tslib": "^2.3.0"
},
"resolutions": {
"axios": "0.27.2"
Expand All @@ -81,7 +81,6 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.12.13",
"@nrwl/jest": "15.0.3",
"semantic-release": "^19.0.5",
"@semantic-release/github": "^8.0.6",
"@storybook/addon-knobs": "^6.4.0",
"@svgr/webpack": "^6.2.1",
Expand Down Expand Up @@ -121,6 +120,7 @@
"react-select-event": "^5.5.1",
"react-test-renderer": "18.2.0",
"redux-mock-store": "^1.5.4",
"semantic-release": "^19.0.5",
"storybook-tailwind-dark-mode": "^1.0.15",
"ts-jest": "28.0.5",
"ts-node": "10.9.1",
Expand Down

0 comments on commit ddb40e1

Please sign in to comment.