I am following Dan Abramov's tutorial on Redux. (https://egghead.io/lessons/javascript-redux-avoiding-object-mutations-with-object-assign-and-spread)
In lesson's 9 he introduces testing and using expect
and .toEqual()
This is my code:
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.')
and I keep getting an error:
.../react_redux/src/a.js:24
).toEqual(todoAfter)
^
TypeError: expect(...).toEqual is not a function
What am I doing wrong? I am copying his code verbatim, but it leads to errors.
For me, my .toEqual
was following the wrong brackets. Make sure it's expect(...).toEqual(..)
, and not expect(...(...).toEqual(...))
in my case to make it work I done following:
1. npm install --save expect install package from npm
2. import expect from 'expect'; import lib in file
3. expect(toggleTodo(stateBefore, action)).toEqual(stateAfter);
Not sure if the provided syntax was ever correct for the chai
library. (I would assume they are using some other assertion library)
The way the equality should be checked with its expect
function is
expect(toggleTodo(todoBefore)).to.equal(todoAfter);
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With