gpt4 book ai didi

javascript - TypeError : expect(. ..).toEqual 不是函数

转载 作者:行者123 更新时间:2023-11-29 19:05:08 25 4
gpt4 key购买 nike

我正在关注 Dan Abramov 关于 Redux 的教程。 ( https://egghead.io/lessons/javascript-redux-avoiding-object-mutations-with-object-assign-and-spread )

在第 9 课中,他介绍了测试和使用 expect.toEqual()

这是我的代码:

var expect = require('chai').expect;
var freeze = require('deep-freeze-node');

const testToggleTodo = () => {
const todoBefore = {
id: 0,
text: 'Learn Redux',
completed: false
};

const todoAfter = {
id: 0,
text: 'Learn Redux',
completed: true
};

expect(
toggleTodo(todoBefore)
).toEqual(todoAfter)
}

testToggleTodo();
console.log('All tests passed.')

我不断收到错误:

.../react_redux/src/a.js:24
).toEqual(todoAfter)
^

TypeError: expect(...).toEqual is not a function

我做错了什么?我正在逐字复制他的代码,但它会导致错误。

最佳答案

对我来说,我的 .toEqual 跟在错误的括号后面。确保它是 expect(...).toEqual(..),而不是 expect(...(...).toEqual(...))

关于javascript - TypeError : expect(. ..).toEqual 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43529086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com