Skip to content

Commit

Permalink
add explicit cleanup and turn off rtl linting rule
Browse files Browse the repository at this point in the history
  • Loading branch information
b-cooper committed Feb 6, 2024
1 parent 73dadf3 commit 59f0263
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ module.exports = {
env: { jest: true },
extends: ['plugin:testing-library/react'],
rules: {
'testing-library/no-manual-cleanup': 'off',
'testing-library/prefer-screen-queries': 'warn',
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import * as React from 'react'
import { describe, it, beforeEach, afterEach, vi } from 'vitest'
import { screen } from '@testing-library/react'
import { screen, cleanup } from '@testing-library/react'
import { renderWithProviders } from '../../../../__testing-utils__'
import { getHeaterShakerLabwareOptions } from '../../../../ui/modules/selectors'
import { i18n } from '../../../../localization'
import { HeaterShakerForm } from '../HeaterShakerForm'
import type { DropdownOption } from '@opentrons/components'

vi.mock('../../../../ui/modules/selectors')
vi.mock('../../fields', async () => {
const actualFields = await vi.importActual('../../fields')
vi.mock('../../../../ui/modules/selectors', async (importOriginal) => {
const actualFields = await importOriginal<typeof import('../../../../ui/modules/selectors')>()
return {
...actualFields,
getHeaterShakerLabwareOptions: vi.fn()
}
})
vi.mock('../../fields', async (importOriginal) => {
const actualFields = await importOriginal<typeof import('../../fields')>()

return {
...actualFields,
StepFormDropdown: vi.fn(() => <div>mock step form dropdown field!</div>),
TextField: vi.fn(({children}: {children: React.ReactNode}) => <div>mock {children} input!</div>),
ToggleRowField: vi.fn(({children}: {children: React.ReactNode}) => <div>mock {children} toggle!</div>),
TextField: vi.fn((p) => {
return (<div>{`mock ${p.name} input!`}</div>)
}),
ToggleRowField: vi.fn(({ name }) => (<div>{`mock ${name} toggle!`}</div>)),
}
})

Expand Down Expand Up @@ -100,7 +108,8 @@ describe('HeaterShakerForm', () => {
)
})
afterEach(() => {
vi.resetAllMocks()
vi.restoreAllMocks()
cleanup()
})
it('should render a title', () => {
render(props)
Expand All @@ -112,32 +121,32 @@ describe('HeaterShakerForm', () => {
})
it('should render a set temperature toggle', () => {
render(props)
screen.getByText('mock set temp toggle!')
screen.getByText('mock setHeaterShakerTemperature toggle!')
})
it('should render a temperature input when the temperature toggle is ON', () => {
props.formData = {
...props.formData,
setHeaterShakerTemperature: true,
}

render(props)
screen.getByText('mock temp input!')
screen.getByText('mock targetHeaterShakerTemperature input!')
})
it('should render a set shake toggle', () => {
render(props)
screen.getByText('mock set shake toggle!')
screen.getByText('mock setShake toggle!')
})
it('should render a RPM input when the set shake toggle is ON', () => {
props.formData = {
...props.formData,
setShake: true,
}

render(props)
screen.getByText('mock RPM input!')
screen.getByText('mock targetSpeed input!')
})
it('should render a set latch toggle', () => {
render(props)
screen.getByText('mock set latch toggle!')
screen.getByText('mock latchOpen toggle!')
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it } from "vitest"

describe('MagnetForm', () => {
it.todo('replace deprecated enzyme test')
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it } from "vitest"

describe('MixForm', () => {
it.todo('replace deprecated enzyme test')
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it } from "vitest"

describe('SourceDestFields', () => {
it.todo('replace deprecated enzyme test')
})
4 changes: 2 additions & 2 deletions vwdeweditest.config.ts → vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import viteConfig from './vite.config'

export default mergeConfig(viteConfig, defineConfig({
test: {
// environment: 'jsdom',
environment: 'jsdom',
exclude: [
...configDefaults.exclude,
'**/node_modules/**',
'**/dist/**'
]
],
},
resolve: {
alias: {
Expand Down

0 comments on commit 59f0263

Please sign in to comment.