Invalid Chai property in Vitest
Full error message
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?Solutionsource: stackoverflow \u2197
First you need to create setupTests.js file, then connect it to the config. You may have to install jsdom as a dependency to the project. setupTests.js import '@testing-library/jest-dom'; vite.config.js import { defineConfig } from 'vite'; export default defineConfig({ test: { globals: true, environment: "jsdom", setupFiles: ["./setupTests.js"], }, }); links: Github problem and Configuring Vitest
API access
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/d2de6585141c11a281448dc162a1932fc3e04a42483dbf9ffa6c8f437bcab6dbhash \u00b7 d2de6585141c11a281448dc162a1932fc3e04a42483dbf9ffa6c8f437bcab6db