我跟随this egghead tutorial并在控制台中收到错误:
"ReferenceError: expect is not defined
at testToggleTodo (myproj.js:18:3)
at myproj.js:25:1
at https://static.jsbin.com/js/prod/runner-4.0.4.min.js:1:13850
at https://static.jsbin.com/js/prod/runner-4.0.4.min.js:1:10792"
我的HTML :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://wzrd.in/standalone/expect@latest"></script>
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script>
</head>
<body>
</body>
</html>
ES6 / Babel :
const toggleTodo = (todo) => {
todo.completed = !todo.completed;
return todo;
};
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.');
您可以在我的HTML的expect
中看到我已导入head
:
<script src="https://wzrd.in/standalone/expect@latest"></script>
为什么我仍然收到错误?我在这里缺少什么?
感谢。