Skip to content

Cursors position not reset between tests?Β #35

@geritol

Description

@geritol

In this test:

import React from 'react';
import { describe, expect, test } from 'vitest';
import { render } from 'vitest-browser-react';
import './aa.css';

const TestComponent = (props: {children: any }) => {
    return <div className='aa' role='button' style={{width: 100, height: 50}}>{props.children}</div>
}

describe('Test', () => {
	test('default', async () => {
		const { container } = await render(<TestComponent>default</TestComponent>);
		await expect.element(container).toMatchScreenshot('default');
	});
	test('default hower', async () => {
        const screen = await render(<TestComponent>default</TestComponent>);
		await screen.getByRole('button').click();
		await expect.element(screen.container).toMatchScreenshot('default-expanded');
	});
	test('default again', async () => {
		const { container } = await render(<TestComponent>default</TestComponent>);
		await expect.element(container).toMatchScreenshot('default again');
	});
});

aa.css

.aa {
    background-color: blue;
    &:hover {
        background-color: yellow;
    }
}

The screenshot of default again will have the element with yellow background even if there was no interaction with that element in that test.

Image

When default again is tagged with .only the test creates the expected screenshot with blue bg.

Image

To me it seems it might be because cursor position is leaking between the tests, and since the previous test clicked an element in that position, next test is affected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions