I have this test (React, Vitest & Testing Library):
import { describe, expect, it } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
describe('App button Problem', () => {
it('types in the input correctly', async () => {
render(<input type={'text'} disabled={false}/> );
const input : HTMLInputElement = screen.getByRole('textbox');
fireEvent.input(input, { target: { value: 'test' } });
expect( input.value).toBe('test'); // this is ok
});
it('does not types in the input if disabled', async () => {
render(<input type={'text'} disabled={true}/> );
const input : HTMLInputElement = screen.getByRole('textbox');
fireEvent.input(input, { target: { value: 'test' } });
expect( input.value).toBe(''); // this fails (why?)
});
});
I get this error:
AssertionError: expected 'test' to be '' // Object.is equality
Expected :
Actual :test
Any idea why?