I’m trying to use expect.toClose
from Vitest, but I’m getting TypeError: expect.closeTo is not a function
.
According to the Typescript checks Property 'closeTo' does not exist on type 'ExpectStatic'.ts(2339)
.
I’m using a fresh SvelteKit project with Vitest by default. The only change I’ve done was in the index.test.ts:
import { describe, it, expect } from "vitest";
describe("sum test", () => {
it("adds 1 + 2 to equal 3", () => {
expect({ value: 1 + 2 }).toBe({
value: expect.closeTo(3),
});
});
});
The dependencies are:
{
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.27.4",
"svelte": "^4.0.5",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.4.2",
"vitest": "^0.34.0"
}
}
This seems like a recent issue, and it’s probably fixed in the latest version.
Update your vitest to 0.34.6
I’m not sure if it should work in version 0.34. At least it works at 1.0.0-beta.4