-1

我的控制台的输出。请注意,控制台日志是乱序的(1,3,4,2 而不是 1,2,3,4)

![在此处输入图像描述

代码在这里

  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)
    })

  })
4

2 回答 2

1

结果证明这是一个愚蠢的错字。我输入fullfilled而不是fulfilled

于 2016-05-30T16:16:26.297 回答
-1

我怀疑你从柴那里得到了副作用。首先尝试不使用它进行测试,例如:

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 知道如何处理返回的 Promise,所以真的不需要 Chai。这是不必要的糖。

于 2016-05-30T06:53:53.047 回答