-1

An output of my console. Note that the console logs are out of order (1,3,4,2 instead of 1,2,3,4)

![enter image description here

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

  })
A F
  • 7,424
  • 8
  • 40
  • 52
  • What's the code of `filestore.store.q`? I've used Chai-as-Promised extensively. Never had a problem with it. – Louis May 29 '16 at 20:53
  • It would take a lot of work to add that code here in a meaningful way (its a ver complicated function). However its definetetly returning a proper promise as evident by 1) the then function fires and 2) chai-as-promised accepts it as fulfilled – A F May 29 '16 at 20:57
  • What is `.bignumber`? – Bergi May 29 '16 at 21:42
  • its from chai-bignumber – A F May 29 '16 at 21:53

2 Answers2

1

This turned out to be a stupid typo. I typed fullfilled instead of fulfilled

A F
  • 7,424
  • 8
  • 40
  • 52
-1

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. It's unnecessary sugar.

Andrew Eddie
  • 988
  • 6
  • 15