类型错误:expect(...).toEqual 不是函数

Mor*_*len 6 javascript

我正在关注 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.')
Run Code Online (Sandbox Code Playgroud)

我不断收到错误消息:

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

TypeError: expect(...).toEqual is not a function
Run Code Online (Sandbox Code Playgroud)

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

Dr-*_*ket 10

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


zer*_*kms 1

不确定提供的语法对于该chai库是否正确。(我假设他们正在使用其他一些断言库)

应使用其函数检查相等性的方法expect

expect(toggleTodo(todoBefore)).to.equal(todoAfter);
Run Code Online (Sandbox Code Playgroud)

参考: