mocha

例子

其他关键词

碰到的问题

如何测试es6的module

出现如下报错

1
2
3
4
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)

1
$ ./node_modules/mocha/bin/mocha --require babel-register --require babel-polyfill

mocha --compilers js:babel-register 已经废弃。具体见compilers deprecation

相关issue SyntaxError: Unexpected token import #3228 ES6 import not working when using babel in Mocha. #2655 Babel unexpected token import when running mocha tests

Move the invocation into the parens that contain the function wrap-iife

异步的回调没有添加done()

1
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

如果确实耗时过长的的设置--timeoutthis.timeout(3000);

相关issue timeout of 2000ms exceeded. Ensure the done() callback is being called in this test. #2025

其他

ReferenceError: window is not defined

get request
(node:13054) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 63): [object Object]

推荐阅读

参考文档