I'm trying to figure it out why meteor testing with mocha does not work with async meteor methods, every time I run this error comes up:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
I tried even with the old style mocha async testing, using done callback but it didn't work.
This is the spec:
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, err) => {
expect(res).to.be.null;
expect(err).to.not.be.null;
});
});
});
}
I am running this tests with:
meteor test --once --driver-package dispatch:mocha-phantomjs
I have the following versions but I tried with the most recent ones:
dispatch:mocha-phantomjs@0.1.7
dispatch:phantomjs-tests@0.0.5
What am I missing?
Aucun commentaire:
Enregistrer un commentaire