I am following Dan Abramov's tutorial on Redux. ()
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.
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.
Share Improve this question asked Apr 20, 2017 at 20:15 dropWizarddropWizard 3,53812 gold badges69 silver badges92 bronze badges 1- The source of truth is always in the official documentation not in someone's blog: chaijs.com/guide/styles/#expect – zerkms Commented Apr 20, 2017 at 20:30
4 Answers
Reset to default 11For 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:
- http://chaijs.com/api/bdd/#method_equal
was using the wrong package
shouldn't use chai,
import expect from 'expect'