我不明白为什么测试失败



我看过笑话和酶文档,不知道还能在哪里找到如何做到这一点。

测试如下:

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);
});});

以下是console.log(wrapper.debug(((的输出

<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>

根据Jest的文档,该方法实际上被称为toHaveLength:

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

另一方面,Enzyme的文档使用Chai断言中的expect,该断言具有to.have.lengthOf

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

选择JestChai编写此单元测试。

最新更新