简体   繁体   English

React Storybook 仅显示三个单元测试

[英]React Storybook showing only three unit tests

I am facing a very strange situation.我面临着一个非常奇怪的情况。 I have 9 unit tests that are running perfectly well when I run it through jest command.当我通过 jest 命令运行它时,我有 9 个单元测试运行良好。 But when I run storybook it just shows 3 tests out of 9. Storybook version is 5.1.7 .但是当我运行 storybook 时,它只显示 9 个测试中的 3 个。 Storybook 版本是5.1.7

截屏

Test which is showing on storybook - Filter Search Orders -显示在故事书上的测试 - 过滤搜索订单 -

import React from "react";
import expect from "expect";
import { mount } from "enzyme";
import _ from "lodash";

import Root from "../../root";
import { storiesOf, describe, it, specs, beforeEach, afterEach } from "../../../.storybook/facade";
import FilterSearchOrders from "../search-orders/filter-search-orders";
import ordersFilterOptions from "../search-orders/orders-filters-options";

const filterSearchOrdersInfo = {
  searchedText: "",
  status: "",
  pageNo: 0,
};

const getElement = () => {
  return (
    <Root>
      <FilterSearchOrders
        searchedText={filterSearchOrdersInfo.searchedText}
        status={filterSearchOrdersInfo.status}
        pageNo={filterSearchOrdersInfo.pageNo}
      />
    </Root>
  );
};

storiesOf("Filter Search Orders", module).add("Filter Search Orders", () => {
  specs(() =>
    describe("Test case for filter search order component", () => {
      let wrapper;

      beforeEach(() => {
        wrapper = mount(getElement());
      });

      afterEach(() => {
        wrapper.unmount();
      });

      it("should render an input box for searching", () => {
        expect(wrapper.find(".search-orders-input"));
      });

      it("should render a dropdown with options", () => {
        const dropdownOptions = wrapper.find(".item").map((node) => node.text());
        const items = _.map(ordersFilterOptions, _.property("text"));

        expect(dropdownOptions).toEqual(items);
      });

      it("should render a primary button called search", () => {
        expect(wrapper.find(".primary").text()).toEqual("SEARCH");
      });
    })
  );
  return getElement();
});

Test not showing on storybook - Menu story -测试未显示在故事书上 - 菜单故事 -

    import React from "react";
    import expect from "expect";
    import { mount } from "enzyme";
    import _ from "lodash";

    import { DASHBOARDITEMS } from "../menu/menuItems";
    import { storiesOf, describe, it, specs } from "../../../.storybook/facade";
    import NavBar from "../menu";
    import Root from "../../root";

    const getElement = () => {
      return (
        <Root>
          <NavBar items={DASHBOARDITEMS} />
        </Root>
      );
    };

    storiesOf("Menu", module).add("Navigation Bar component", () => {
      specs(() =>
        describe("Main menu", () => {
          it("should render menu", () => {
            const wrapper = mount(getElement());

            expect(wrapper.find(".nestedMenu"));


    });

      it("should render an image to show logo", () => {
        const wrapper = mount(getElement());

        expect(
          wrapper
            .find(".item")
            .at(0)
            .find("img").length > 0
        ).toEqual(true);
      });

      it("should render all links", () => {
        const wrapper = mount(<Root>{getElement()}</Root>);
        const links = wrapper.find("a").map((node) => node.text());
        const items = _.map(DASHBOARDITEMS, _.property("content"));

        expect(links).toEqual(items);
      });
    })
  );
  return getElement();
});

Okay so I seemed to figure out what was wrong the whole time.好的,所以我似乎一直在弄清楚出了什么问题。

A very stupid mistake by me but I hope it helps anyone who is dealing with same issue.我犯了一个非常愚蠢的错误,但我希望它可以帮助任何处理相同问题的人。

I checked the console and seems like the fourth story (in order) that I had written had some error and as soon as I resolved that error that story itself and all other story started showing on storybook.我检查了控制台,似乎我写的第四个故事(按顺序)有一些错误,一旦我解决了这个错误,这个故事本身和所有其他故事就开始在故事书中显示。

I upgraded my storybook version and seems like all the stories are shown on the UI with errors.我升级了我的故事书版本,似乎所有的故事都显示在 UI 上,但有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM