Mocha Promise测试流星方法不起作用

时间:2017-02-07 15:28:47

标签: javascript testing meteor mocha

我正在试图弄明白为什么使用mocha进行流星测试时不能使用异步流星方法,每次运行此错误都会出现:

Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.

我尝试使用旧式mocha异步测试,使用完成回调但它没有用。

这是规范:

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 test --once --driver-package dispatch:mocha-phantomjs

我有以下版本,但我尝试了最新的版本:

dispatch:mocha-phantomjs@0.1.7
dispatch:phantomjs-tests@0.0.5

我错过了什么?

0 个答案:

没有答案