【问题标题】:React Typescript facing issue with enzyme [duplicate]React Typescript面临酶问题[重复]
【发布时间】:2020-10-22 08:12:10
【问题描述】:

我有一个组件 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)

我已尝试进行故障排除,但无法找到解决方法

【问题讨论】:

    标签: reactjs typescript jestjs enzyme


    【解决方案1】:

    在添加chai library 之前,没有.to. 方法。开玩笑own matchers.toHaveLength() 你可以使用:

    expect(app.find('div.head')).toHaveLength(1);
    

    【讨论】:

      猜你喜欢
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      • 2022-09-25
      • 2022-07-29
      相关资源
      最近更新 更多