不确定我为什么会收到错误:
'use strict';
/**
* Module dependencies.
*/
var should = require('should'),
mongoose = require('mongoose'),
Block = mongoose.model('Block');
//Globals
var block;
//The tests
describe('<Unit Test>', function() {
describe('Model Block:', function() {
beforeEach(function(done) {
block = new Block({
bits: "1d00ffff",
block_fee: 0,
blockreward: 50,
coinbase: 50,
difficulty: 1,
fees_claimed: 0,
fees_paid: 0,
hash: "000000005c51de2031a895adc145ee2242e919a01c6d61fb222a54a54b4d3089",
height: 13,
merkleroot: "9962d5c704ec27243364cbe9d384808feeac1c15c35ac790dffd1e929829b271",
nextblockhash: "0000000080f17a0c5a67f663a9bc9969eb37e81666d9321125f0e293656f8a37",
nonce: 2259603767,
previousblockhash: "0000000027c2488e2510d1acf4369787784fa20ee084c258b58d9fbd43802b5e",
size: 215,
time: 1231475020,
time_to_confirm: 132,
tx: [
"9962d5c704ec27243364cbe9d384808feeac1c15c35ac790dffd1e929829b271"
],
txcount: 1,
version: 1,
vin_total: 0,
vout_total: 50
});
});
describe('Method Save', function() {
it('should be able to save without problems', function(done) {
return block.save(function(err) {
should.not.exist(err);
done();
});
});
it('should be able to show an error when try to save without hash', function(done) {
block.hash = '';
return block.save(function(err) {
should.exist(err);
done();
});
});
});
afterEach(function(done) {
Block.remove({});
done();
});
after(function(done) {
Block.remove().exec();
done();
});
});
});
那是我的model.js
测试文件。我得到的错误是:
<Unit Test>
Model Block:
Method Save
1) "before each" hook
0 passing (2s)
1 failing
1) <Unit Test> Model Block: "before each" hook:
Error: timeout of 2000ms exceeded
不确定为什么它需要2秒钟或者什么是2秒钟。我怎么才能知道为什么会有这么长时间?
答案 0 :(得分:1)
它告诉你 花了这么长时间。这条消息:
<Unit Test> Model Block: "before each" hook:
对应此beforeEach
来电:
describe('<Unit Test>', function() {
describe('Model Block:', function() {
beforeEach(function(done) {
block = new Block({
//....
如果你想知道为什么需要这么长时间,你可以在new Block
执行的行上设置一个断点并逐步执行它。