【发布时间】:2018-08-14 05:52:38
【问题描述】:
我是使用 jest 测试 react-native 代码的新手,我想实现这个简单的测试。我有以下代码,我想测试如果data === '0' 则返回值null。
export class Test extends Component {
...
_renderRow (data) {
if (data === '0') {
return null
}
return //other item
}
...
}
我尝试了以下测试,但它仍在读取return //other item,因为上面有一个数据变量。
const _renderRowSpy = jest.spyOn(Feed.prototype, '_renderRow')
it('should be null', () => {
function callback(data) {
expect(data.type()).to.equal(null);
}
_renderRowSpy(callback);
});
【问题讨论】:
-
有什么建议我可以在测试中编写条件,或者只是读取 if 语句中的值?
标签: javascript react-native testing jestjs enzyme