Reputation: 413
At work we are using Karma-Mocha with Chai-Enzyme to unit test our react code. 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}
Upvotes: 0
Views: 486
Reputation: 35553
I'm assuming that the ternary expression is part of some JSX element.
So you can use Enzyme's text method in order to extract the text of the element.
import mount from 'enzyme';
describe('example text', () => {
it('should show', () => {
const wrapper = mount( <MyComp> );
expect(wrapper.text()).to.be('DefaultString');
});
});
Upvotes: 1