Here is the working example: https://codesandbox.io/s/30jp9vk67qimport React from "react";import { shallow, mount } from "enzyme";import List from "./ListItem";import Enzyme from "enzyme";import axios from "axios";import MockAdapter from "axios-mock-adapter";describe("List Components", () => { var mock = new MockAdapter(axios); beforeEach(() => { mock .onGet("https://biz.timesofindia.indiatimes.com/bankifsc/getlist") .reply(200, { data: [{ text_val: "a" }, { text_val: "b" }] }); }); describe("List Items", () => { it("check length", () => { const wrapper = shallow(<List />); console.log("Wrapper-Before-", wrapper.debug()); wrapper.setState({ items: [{ text_val: "a" }, { text_val: "b"}]}) console.log("Wrapper-After-", wrapper.debug()); expect(wrapper.find("li").length).toBe(2); }); });}); 这篇关于为什么React JS中的实际长度和预期长度不相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 14:01