Javascript 如何将@testing library/jest dom添加到svelte中的每个测试文件中?

Javascript 如何将@testing library/jest dom添加到svelte中的每个测试文件中?,javascript,unit-testing,svelte,jest-dom,Javascript,Unit Testing,Svelte,Jest Dom,我试图将jest dom库添加到每个测试文件中。 我安装了这个包,创建了“jestSetup.js”文件,并添加了package.json,如下所示 "jest":{ setupFilesAfterEnv:["<rootDir>/jestSetup.js"] } 测试文件是 import { render } from "@testing-library/svelte"; ... console.log("

我试图将jest dom库添加到每个测试文件中。 我安装了这个包,创建了“jestSetup.js”文件,并添加了package.json,如下所示

"jest":{
   setupFilesAfterEnv:["<rootDir>/jestSetup.js"]
}
测试文件是

import { render } from "@testing-library/svelte";
...
console.log("test")
expect(getByText("success notification")).toHaveClass("success");
...
但是它说,
toHaveClass没有定义
error 并且console.log的结果是“jest dom,jest” 我用jest.config.js再次测试了它,但结果是一样的。 我不知道为什么会这样

import { render } from "@testing-library/svelte";
...
console.log("test")
expect(getByText("success notification")).toHaveClass("success");
...