【发布时间】:2017-05-26 03:55:13
【问题描述】:
我正在使用酶和 chai 为我的 reactjs-app 创建一个单元测试:
const wrapper = shallow(
<MyComp {...props}>
</MyComp>
);
expect(wrapper.debug()).to.contain("hello");
我怎样才能断言单词“hello”恰好出现 1 次?
【问题讨论】:
-
我相信我们可以跳过 chai 的
contain并做类似expect((wrapper.debug().match(/hello/g) || []).length).to.equal(1)的事情以获得灵活性。
标签: javascript unit-testing reactjs chai enzyme