I have this Vitest test:
import React from 'react';
import { expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { StyledNativeTimePicker } from
'../timePicker/StyledNativeTimePicker.jsx';
...
it('Shows the time correctly', async () => {
const time = '12:00';
render(
<StyledNativeTimePicker
time={time}
timeChanged={() => {}}
></StyledNativeTimePicker>
);
const testInput = screen.getByRole('input', { type: 'time' });
expect(testInput).toHaveValue(time);
});
...
Now I get this error Error: Invalid Chai property: toHaveValue
. Any Idea why when Chai is not installed?
First you need to create
setupTests.js
file, then connect it to the config. You may have to installjsdom
as a dependency to the project.setupTests.js
vite.config.js
links: Github problem and Configuring Vitest