[英]how to unit test a basic ternary using karma-mocha/chai-enzyme?
At work we are using Karma-Mocha with Chai-Enzyme to unit test our react code. 在工作中,我们将Karma-Mocha与Chai-Enzyme一起使用来对我们的反应代码进行单元测试。 I'm hoping some one could give me a basic example on how to unit test a basic ternary. 我希望有人能给我一个有关如何对基本三元进行单元测试的基本示例。
Example ternary such as this: 这样的示例三元:
{myVariable === null ? 'DefaultString' : myVariable}
I'm assuming that the ternary expression is part of some JSX element. 我假设三元表达式是某些JSX元素的一部分。
So you can use Enzyme's text method in order to extract the text of the element. 因此,您可以使用酶的text方法来提取元素的文本。
import mount from 'enzyme'; describe('example text', () => { it('should show', () => { const wrapper = mount( <MyComp> ); expect(wrapper.text()).to.be('DefaultString'); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.