流星摩卡测试失败

时间:2018-05-09 01:59:43

标签: javascript node.js meteor mocha

我目前正在为我刚创建的流星project运行mocha测试,其中Mocha测试失败。

测试的源代码是:

import StubCollections from 'meteor/hwillson:stub-collections';
import { chai } from 'meteor/practicalmeteor:chai';

import { resetDatabase } from 'meteor/xolvio:cleaner';
import {getNewNonce} from '/app/client/getNewNonce';

import {getNonceDoc, Nonces} from '/app/lib/collections/nonces';

StubCollections.stub(Nonces);

Array.prototype.sub = function( b ) {
  var a = this,
    c = [];
  if( Object.prototype.toString.call( b ) === '[object Array]' ) {
    if( a.length !== b.length ) {
      throw new Error("Array lengths do not match.");
    } else {
      for( var i = 0; i < a.length; i++ ) {
        c[ i ] = a[ i ] - b[ i ];
      }
    }
  } else if( typeof b === 'number' ) {
    for( var i = 0; i < a.length; i++ ) {
      c[ i ] = a[ i ] + b;
    }
  }
  return c;
};

// Utility -- returns a promise which resolves when all subscriptions are done
const waitForSubscriptions = () => new Promise(resolve => {
  const poll = Meteor.setInterval(() => {
    if (DDP._allSubscriptionsReady()) {
      Meteor.clearInterval(poll);
      resolve();
    }
  }, 200);
});

describe('ever increasing nonce test', async function () {
  beforeEach(async () => {
    resetDatabase();
    await waitForSubscriptions();
    if (!Nonces.findOne())
      Nonces.insert(getNonceDoc(0));
  });

  it('should be ok', async function () {
    let integersList = Array.from(Array(1000).keys());
    let nonceList = await integersList.map((aNumber) => getNewNonce());
    let resolvedNonceList = await Promise.all(nonceList);
    // let nonShiftedSubList = nonceList.slice(1);
    // let shiftedForwardList = nonceList.slice(0,nonceList.length-1);
    //
    // let delta = nonShiftedSubList.sub(shiftedForwardList);
    // let isEvery = delta.every((aDelta) => aDelta > 0);
    // console.log(isEvery);
    // isEvery.should.be(true);
    // integersList.length.should.be(1000);
  })
});

目前,当我运行npm test时,浏览http://localhost:3000/时的测试结果如下:

Meteor mocha tests result

转录错误:

Error: Method 'updateNonce' not found [404]Error
   at errorClass (packages/meteor.js?hash=c9a34f92f28ede5a42eac467d3fa1763b624436a:622:7)
   at _livedata_result (packages/ddp-client.js?hash=53be61ea50e289ef291ca3b87b6968a50594ce80:1964:9)
   at onMessage (packages/ddp-client.js?hash=53be61ea50e289ef291ca3b87b6968a50594ce80:2158:9)
   at Anonymous function (packages/socket-stream-client.js?hash=f8b39dfba9fdeafe7c1ee49d011814e2bb921087:263:13)
   at Array.prototype.forEach (native code)
   at forEachCallback (packages/socket-stream-client.js?hash=f8b39dfba9fdeafe7c1ee49d011814e2bb921087:356:7)
   at socket.onmessage (packages/socket-stream-client.js?hash=f8b39dfba9fdeafe7c1ee49d011814e2bb921087:262:11)
   at REventTarget.prototype.dispatchEvent (packages/socket-stream-client.js?hash=f8b39dfba9fdeafe7c1ee49d011814e2bb921087:646:7)
   at SockJS.prototype._dispatchMessage (packages/socket-stream-client.js?hash=f8b39dfba9fdeafe7c1ee49d011814e2bb921087:1825:5)
   at SockJS.prototype._didMessage (packages/socket-stream-client.js?hash=f8b39dfba9fdeafe7c1ee49d011814e2bb921087:1891:11)

我在这里真正想念的是什么?看起来测试javascript文件无法正确访问Metheor.methods updateNonce

0 个答案:

没有答案