我开始学习 Jest 并完成作业。一个不跳过。我不明白如何实现它。
带来了我的代码
/**
* Write test to check that objects equal after
* calling function boo
*/
const obj1 = {
name: "Test",
};
const obj2 = {
name: "John",
};
const boo = (obj1, obj2) => {
obj1.name = obj2.name;
};
describe("Practicing with tests", () => {
it("objects equal after calling function boo", () => {
boo(obj1, obj2);
console.log(obj1 === obj2);
});
}); // Modify this
利用
expect该方法
toEqual检查对象的属性,比较===只是对这些对象的引用阅读更多
您也可以只比较感兴趣的财产
需要 var 而不是 const:
和:
或者,如您的情况: