Im new to testing react-native code using jest and I want to achieve this simple test. I have the following code and I want to test that if data === '0'
then return value null
.
export class Test extends Component {
...
_renderRow (data) {
if (data === '0') {
return null
}
return //other item
}
...
}
I tried the following test, but its still reading the return //other item
since there is a data variable on it.
const _renderRowSpy = jest.spyOn(Feed.prototype, '_renderRow')
it('should be null', () => {
function callback(data) {
expect(data.type()).to.equal(null);
}
_renderRowSpy(callback);
});
Okay, got some help from a very good friend. Here's the solution if someone has similar test.
it('should be null', () => {
const instance = wrapper.instance()
const result = instance._renderRow('0')
expect(result).toBe(null)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With