Reputation: 2014
i have following reactjs code snippet:
import lionIcon from 'assets/images/lion.svg';
import dogIcon from 'assets/images/dog.svg';
<img
className="animal-btn-img"
src={isLion ? lionIcon : dogIcon}
/>
how do i unit test that based on 'isLion' prop, appropriate animal object is set on the img tag.?
let img = wrapper.find('.animal-btn-img');
console.log(img.prop('src'));
the above console.log returns only empty object as {}
Upvotes: 1
Views: 3553
Reputation: 1215
try shallow
from enzyme
, it worked well for me
import React from 'react'
import {shallow} from 'enzyme'
import Testor from '../components/Testor'
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
it('should see image source', () => {
const container = shallow(<Testor/>)
expect(container.find('img').props().src).toEqual('http://google.com/')
})
Upvotes: 1