酶未在浅层方法中读取道具image_url
。但是它似乎读了'src'属性。
Image.test.js
it('should test for image_url prop', () => {
const url = 'https://res.cloudinary.com/dq281hpqd/image/upload/v1559697741/s3wxjfweznq8kqum2p0x.png';
const wrapper = shallow(<Image image_url={url}/>)
wrapper.setProps({ image_url: url });
// expect(wrapper.prop("src")).toBe(url) // this passes but not the way it should be
// it should check for image_url prop, but the following code is not working
expect(wrapper.prop('image_url')).toBe(url);
})
Image.js
import React from "react";
const Image = (props) => (
<img width="100%" height="100%" alt="stuff" src = {props.image_url} />
)
export default Image
答案 0 :(得分:1)
尝试
expect(wrapper.props().image_url).to.equal(url);
不确定为什么要测试URL。
你可以
expect(wrapper).toMatchSnapshot(); // this will cover whole image component.