我有一个 Logo 组件:
import React from "react";
import logo from "assets/images/logo.png";
const Logo = () => {
return <img style={{ width: 50 }} src={logo} alt="logo" />;
};
export default Logo;
测试文件:
import React from "react";
import Logo from "components/shared/Logo";
describe("<Logo />", () => {
it("renders an image", () => {
const logo = shallow(<Logo />);
expect(logo.find("img").prop("src")).toEqual("blahh");
});
});
但是当我运行测试时,出现了一些奇怪的错误:
$ NODE_PATH=src jest
FAIL src/tests/Logo.test.js
● <Logo /> › renders an image
TypeError: val.entries is not a function
at printImmutableEntries (node_modules/expect/node_modules/pretty-format/build/plugins/immutable.js:44:5)
at Object.<anonymous>.exports.serialize (node_modules/expect/node_modules/pretty-format/build/plugins/immutable.js:178:12)
我应该如何测试图像 src === "assets/images/logo.png"?