我有一个组成部分
app.tsx
import React, { useState } from "react";
const TestCom = () => {
return(
<>
<div className="head">hey there</div>
<select name="xyz" id="uni">
<option value="abc">abc</option>
</select>
</>
)
}
export default TestCom
我正在用玩笑和酵素测试它
app.test.tsx
import TestCom from "./foo";
import { shallow } from 'enzyme';
import React from "react";
test("basic test", () => {
const app= shallow(<TestCom />)
expect(app.find('div.head')).to.have.lengthOf(1);
});
每当我使用.to引发错误
Property 'to' does not exist on type 'JestMatchersShape<Matchers<void, ShallowWrapper<HTMLAttributes,
any, Component<{}, {}, any>>>, Matchers<Promise<void>, ShallowWrapper<HTMLAttributes, any,
Component<...>>>>'.ts(2339)
我已尝试进行故障排除,但找不到解决方法
答案 0 :(得分:2)
在添加chai library之前,没有.to.
方法。笑话own matchers有.toHaveLength()
可以使用:
expect(app.find('div.head')).toHaveLength(1);