简体   繁体   English

我不明白为什么测试失败

[英]I can't understand why test is failing

I've looked at jest and enzyme documentation and don't know where else to find out how to do this.我查看了笑话和酶文档,不知道在哪里可以找到如何做到这一点。

Heres the test:下面是测试:

describe('The tile grid displays the tile container when there is no error and it is 
not loading', () => {
  let wrapper;
  beforeEach(() => {
    const defaultProps = {
      ...TileGridDefaultPropsInit,
 
    };
   wrapper = shallow(<TileGrid  {...defaultProps} />);

    console.log(wrapper.debug());
 });

  it('it displays the tile grid container', () => {
    expect(wrapper.find('.tile-grid__container')).toHaveLengthOf(1);
  });});

Heres the output from console.log(wrapper.debug())这是来自 console.log(wrapper.debug()) 的 output

    <div className="tile-grid">
          <div className="tile-grid__heading">
            Top Stories
          </div>
          <div className="tile-grid__container">
            // theres a load of stories here - too long to put paste onto this question.
            
           
        
      </div>
    </div>

According to documentation from Jest , the method is actually called toHaveLength :根据来自Jest的文档,该方法实际上被称为toHaveLength

https://jestjs.io/docs/expect#tohavelengthnumber https://jestjs.io/docs/expect#tohavelengthnumber

On the other hand, documentation from Enzyme uses expect from Chai assertion which has to.have.lengthOf另一方面,来自Enzyme的文档使用来自Chai断言的expect ,它必须to.have.lengthOf

https://enzymejs.github.io/enzyme/docs/api/ShallowWrapper/find.html https://enzymejs.github.io/enzyme/docs/api/ShallowWrapper/find.html

Choose either Jest or Chai for writing this unit test.选择JestChai来编写这个单元测试。

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

相关问题 不明白为什么我不能访问计数器的值 - Can't understand why I can't access the value of counter 我无法理解为什么带有'connect()'的组件在响应中是有状态的 - I can't understand why components with 'connect()' are stateful in react 不明白为什么 onClick 不能在 React 中工作 - Can't understand why onClick not working in React 无法理解为什么map()不是函数 - Can't understand why map() is not a function 我不明白我们为什么以及如何向这个函数传递一些东西。 选择器问题 - I can't understand why and how are we passing something to this function. Selector question 功能组件定义 scope 导致应用程序无法正常工作,但我不明白为什么 - Functional Component definition scope causing app to not work correctly, but I can't understand why 不明白为什么我在这个反应循环中只得到一个表格行 - Can't understand why I only get one table row in this react loop FreeCodeCamp Javascript 计算器测试套件 | 我不知道为什么我不能通过这个测试 - FreeCodeCamp Javascript calculator test suite | I don't know why I can't pass this test CodinGame(React 测试):我不明白答案 - CodinGame (React test) : I don't understand the answer 无法在 heroku 上部署 React App,不明白为什么? - Can't deploy React App on heroku, don't understand why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM