【发布时间】:2016-01-05 20:29:22
【问题描述】:
我使用 jest 和 jasmine-pit 来测试我的代码,一切都很棒。
我更新了 jest v0.5.0 -> v0.8.2,但我遇到了相同代码的问题。
这是错误信息: 超时:等待某事发生 5000 毫秒后超时
这是我的代码:
jest.autoMockOff();
var jasminePit = require('jasmine-pit');
jasminePit.install(window);
describe('Test', function() {
pit('testA', function() {
var myItem= new MyClass();
console.log("first text");
return myItem.launch().then(function() {
console.log("second text");
expect(true).toBe(true);
});
});
});
“第一个文本”在控制台中写入,“第二个文本”永远不会写入,并且我有超时错误消息。
jest 0.5.0 一切都很好。
有什么想法吗??
编辑
您好,我使用的是 node.js v5.0.0,typescript v1.5.3。我的测试是用 gulp 和 jest-cli 用这条线启动的
var jestConfig = {
scriptPreprocessor:'<rootDir>/../scripts/jtest.preprocessor.js',
rootDir: 'sources',
testFileExtensions: [
"ts",
"js",
"tsx"
],
moduleFileExtensions: [
"js",
"json",
"ts"
]
};
我的 jtest.preprocessor.js:
var ts = require('typescript');
module.exports = {
process: function(src) {
return ts.transpile(src, {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES5,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
jsx: ts.JsxEmit.React,
experimentalDecorators: true
});
}
};
和 gulp 任务:
gulp.task('test-tip', function(done) {
jest.runCLI({ config : jestConfig }, __dirname, function(success) {
console.log(success);
done();
});
});
【问题讨论】:
-
myItem.launch()返回一个永远不会解决的承诺。您可能完全可以在没有任何茉莉花的情况下复制它。 -
感谢您的回答。承诺调用 resolve(),这段代码与 Jest 0.5.0 一起使用。我不明白为什么 myItem.launch() 返回一个承诺然后用 Jest 0.5 而不是 Jest 0.8.2 调用 resolve