简体   繁体   English

如何使用业力摩卡/柴酶对基本三元进行单元测试?

[英]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.

相关问题 在Karma-mocha中没有定义chai - chai is not defined in Karma-mocha 如何使用摩卡茶和酶对道具的状态进行单元测试? - How to unit test the state of props using mocha chai and enzyme? Karma-Mocha-如何测试侦听DOMContentLoaded事件的方法 - Karma-Mocha - How to test method that listens to DOMContentLoaded event 如何将AngularJS服务注入业力摩卡测试 - How to Inject AngularJS service to karma-mocha test 如何使用酶,摩卡,柴对单元自定义的React函数进行单元测试 - How do you unit test a custom React function using enzyme, mocha, chai 单元测试AngularJS指令的控制器(Karma,Chai,Mocha) - Unit Test a AngularJS Directive's Controller (Karma, Chai, Mocha) 如何编写用于使用mongoose,mocha和chai将对象插入和检索到mongodb的单元测试? - How to write a Unit test for inserting and retrieving an object to mongodb using mongoose, mocha and chai? 如何为chai Expect提供用于摩卡单元测试的自定义错误消息? - How to provide chai expect with custom error message for mocha unit test? 如何对路由器功能NodeJS / Mocha / Chai进行单元测试 - How to carry unit test on router function NodeJS / Mocha / Chai 使用standardJS在Mocha Chai单元测试中没有未使用的表达式 - No unused expressions in mocha chai unit test using standardJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM