[英]Chai as promised not waiting for promise to be fulfilled
An output of my console.我的控制台的输出。 Note that the console logs are out of order (1,3,4,2 instead of 1,2,3,4)
请注意,控制台日志是乱序的(1,3,4,2 而不是 1,2,3,4)
Code here代码在这里
it('can store file', () => {
console.log('1) file storage start')
return filestore.store.q(file).then(() => {
console.log('2) file storage done')
}).should.eventually.be.fullfilled
})
describe('block number', () => {
beforeEach(() => {
console.log('3) check blockNumber')
return web3.Q.all([
web3.eth.getBlockNumber.q().then((_blockNumber) => {
blockNumber = _blockNumber
}),
web3.eth.getMining.q().then((isMining) => {
})
])
})
it('can retreive files block number', () => {
console.log('4) retreive')
return filestore.getBlockNumber.q(fileHash).should.eventually.bignumber.equal(blockNumber)
})
})
This turned out to be a stupid typo.结果证明这是一个愚蠢的错字。 I typed
fullfilled
instead of fulfilled
我输入
fullfilled
,而不是fulfilled
I suspect you are getting a side-effect from Chai.我怀疑你从柴那里得到了副作用。 Try testing without it first, for example:
首先尝试在没有它的情况下进行测试,例如:
const assert = require('assert');
it('can store file', () => {
console.log('1) file storage start')
return filestore.store.q(file).then(() => {
// Promise should have fulfilled. Nothing more to do.
// Using should and chai after this is probably causing the problem.
// But you should really add some sort of assertion here to
// be able to detect regressions.
console.log('2) file storage done')
});
});
describe('block number', () => {
let blockNumber;
beforeEach(() => {
console.log('3) check blockNumber')
return web3.Q.all([
web3.eth.getBlockNumber.q().then((_blockNumber) => {
blockNumber = _blockNumber
}),
web3.eth.getMining.q().then((isMining) => {
})
])
})
it('can retreive files block number', () => {
console.log('4) retreive')
return filestore.getBlockNumber.q(fileHash)
.then((result) => {
// I'm not sure if assert.equal will work with big numbers.
// You might need a different comparator here.
assert.equal(result, blockNumber, 'should equal the blocknumber));
});
});
});
Mocha knows how to handle a returned Promise so there's really no need for Chai. Mocha 知道如何处理返回的 Promise,所以真的不需要 Chai。 It's unnecessary sugar.
这是不必要的糖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.