Skip to content

Commit 153fc51

Browse files
lmiller1990Barthélémy Ledoux
and
Barthélémy Ledoux
authored
fix(component-testing): ensure to call unmount after each test (#15385)
* fix: ensure to call unmount after each test * fix: do not append beforeEach * fix: add hook * chore: move unmount hook into npm/react * chore: resolve conflicts * chore: fix tests Co-authored-by: Barthélémy Ledoux <bart@cypress.io>
1 parent e84c995 commit 153fc51

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

npm/react/cypress/component/viewport-spec.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('cy.viewport', () => {
3131
minima libero vel? Nam sequi iusto quod fugit vel rerum eligendi beatae voluptatibus numquam.
3232
</p>)
3333

34-
expect(getComputedStyle(window.parent.document.querySelector('iframe').parentElement).transform).to.contain('matrix(1')
34+
expect(getComputedStyle(window.parent.document.querySelector('iframe').parentElement).transform).to.contain('matrix(0.8')
3535
cy.viewport(2000, 200).should(() => {
3636
expect(getComputedStyle(window.parent.document.querySelector('iframe').parentElement).transform).not.to.contain('matrix(1')
3737
})

npm/react/src/mount.ts

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ export const unmount = (options = { log: true }) => {
166166
})
167167
}
168168

169+
beforeEach(() => {
170+
unmount()
171+
})
172+
169173
/**
170174
* Creates new instance of `mount` function with default options
171175
* @function createMount

npm/vite-dev-server/cypress/components/react-no-jsx.spec.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@ import { mount } from '@cypress/react'
33
import { Foo } from './Foo'
44

55
describe('React', () => {
6-
it('renders a react component', () => {
6+
it('renders a react component #1', () => {
7+
mount(<Foo />)
8+
cy.get('div').contains('Hello world')
9+
})
10+
11+
it('renders a react component #2', () => {
12+
mount(<Foo />)
13+
cy.get('div').contains('Hello world')
14+
})
15+
16+
it('renders a react component #3', () => {
17+
mount(<Foo />)
18+
cy.get('div').contains('Hello world')
19+
})
20+
21+
it('renders a react component #4', () => {
722
mount(<Foo />)
823
cy.get('div').contains('Hello world')
924
})

npm/vite-dev-server/index-template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
Cypress.onSpecWindow(window, importsToLoad)
5959
Cypress.action('app:window:before:load', window)
6060

61-
beforeEach(() => {
61+
before(() => {
6262
const root = appendTargetIfNotExists('__cy_root')
6363

6464
root.appendChild(appendTargetIfNotExists('__cy_app'))

packages/runner-ct/src/app/RunnerCt.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ export const AUT_IFRAME_MARGIN = {
5252

5353
const App: React.FC<AppProps> = observer(
5454
function App (props: AppProps) {
55-
const searchRef = React.createRef<HTMLInputElement>(null)
55+
const searchRef = React.useRef<HTMLInputElement>(null)
5656
const splitPaneRef = React.useRef<{ splitPane: HTMLDivElement }>(null)
5757
const pluginRootContainer = React.useRef<null | HTMLDivElement>(null)
5858

5959
const { state, eventManager, config } = props
6060
const isOpenMode = !config.isTextTerminal
6161

62-
const [isResizing, setIsResizing] = React.useState(false)
63-
6462
const [isSpecsListOpen, setIsSpecsListOpen] = React.useState(isOpenMode)
6563

6664
// const windowSize = useWindowSize()

0 commit comments

Comments
 (0)