Javascript 摩卡承诺测试流星法不起作用
我试图弄明白为什么mocha的meteor测试不能与异步meteor方法一起工作,每次运行时都会出现以下错误:Javascript 摩卡承诺测试流星法不起作用,javascript,testing,meteor,mocha.js,Javascript,Testing,Meteor,Mocha.js,我试图弄明白为什么mocha的meteor测试不能与异步meteor方法一起工作,每次运行时都会出现以下错误: 错误:超过2000毫秒的超时时间。确保在此测试中调用了done()回调。 我甚至尝试了旧式的mocha异步测试,使用done回调,但并没有成功 这是规范: import { assert, expect } from 'meteor/practicalmeteor:chai'; import { resetDatabase } from 'meteor/xolvio:cleaner';
错误:超过2000毫秒的超时时间。确保在此测试中调用了done()回调。
我甚至尝试了旧式的mocha异步测试,使用done回调,但并没有成功
这是规范:
import { assert, expect } from 'meteor/practicalmeteor:chai';
import { resetDatabase } from 'meteor/xolvio:cleaner';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { Promise } from 'meteor/promise';
import { Expenses } from './collection';
import './config';
import './methods';
if (Meteor.isServer) {
describe('expense creation', function () {
beforeEach(function () {
resetDatabase();
});
it('should not be created if there is no budget yet', function () {
const userId = Random.id();
// Find the internal implementation of the task method so we can test it in isolation
const createExpense = Meteor.server.method_handlers['createExpense'];
// Set up a fake method invocation that looks like what the method expects
const invocation = { userId };
const expense = {
description: 'test',
amount: 100,
created: new Date('2017-01-01'),
type: Expenses.types.ESP.code,
user_id: 'examplied'
};
const promise = new Promise((resolve, reject) => {
// Run the method with `this` set to the fake invocation
createExpense.apply(invocation, [expense], (err, res) => {
if (err) reject(err);
resolve(res);
});
});
return promise
.then(res => {
expect(res).to.be.null;
})
.catch(err => {
expect(err).to.not.be.null;
});
});
});
}
我正在使用以下工具运行此测试:
meteor测试——一次——驱动程序包分派:mocha phantomjs
我有以下版本,但我尝试了最新的版本:
dispatch:mocha-phantomjs@0.1.7
dispatch:phantomjs-tests@0.0.5
我错过了什么?你确定考试通过了吗?当考试失败时,我得到了同样的信息。我想我从来没有说过考试是通过的,事实上不是。每次我运行测试套件时,它都会失败。您以前是否遇到过这种情况?承诺只返回1个值,请尝试使用以下内容进行更改:return promission.then(res=>…).catch(err=>…)同意上面的注释,则
then
处理程序只有1个参数。尝试删除最新的期望值,如果有效,请添加一个.catch
处理程序。@MarcoL嘿,我试着按照你说的做,但没有改变。