chai-bignumber icon indicating copy to clipboard operation
chai-bignumber copied to clipboard

should works, expect doesn't

Open PaulRBerg opened this issue 6 years ago • 7 comments

Here's the example from the README:

var result = new BigNumber("100000000000000000").plus(1);
var expected = "100000000000000001";
result.should.be.bignumber.equal(expected);

It works fine. But, if I replace the last line with:

expect(result).to.be.bignumber.equal(expected);

I get the following error:

Error: Invalid Chai property: bignumber

Versions:

• node 10.15.3 • [email protected][email protected]

PaulRBerg avatar Jul 23 '19 15:07 PaulRBerg

any updates? same issue here

amazingandyyy avatar Feb 27 '21 07:02 amazingandyyy

Is chai-bignumberbeing loaded before use?

I am unable to reproduce using the following example:

var BigNumber = require('bignumber.js');
var chai = require('chai');
var expect = require('chai').expect

chai.use(require('chai-bignumber')(BigNumber));

var result = new BigNumber("100000000000000000").plus(1);
var expected = "100000000000000001";
expect(result).to.be.bignumber.equal(expected);

asmarques avatar Feb 27 '21 08:02 asmarques

Any update? Weird, for my setup, this works: var expect = require("../../utils/chai-setup").expect; but this doesn't work: import { expect } from "../../utils/chai-setup";

In "../../utils/chai-setup" I have:

import chaiModule from "chai"; import BN from "bn.js"; chaiModule.use(require("chai-bn")(BN)); export = chaiModule;

colinsteidtmann avatar Nov 02 '21 21:11 colinsteidtmann

Hey @colinsteidtmann, I have not found a solution for this package, but I can wholeheartedly recommend switching to TypeScript. I made the switch in the meantime and it has enhanced my development productivity.

See my solidity-template, which comes with Waffle - a testing framework for Ethereum contracts that includes the functionality implemented by chai-bignumber.

PaulRBerg avatar Nov 02 '21 21:11 PaulRBerg

Hey Paul, that's funny, I'm actually using your template! You just didn't have any examples working with bignumbers so I went looking for a solution. I'll check out chai-bignumber. I love your repo by the way. I customized it a bit with hardhat-deploy and some chainlink libraries.

colinsteidtmann avatar Nov 02 '21 21:11 colinsteidtmann

@colinsteidtmann can you provide a complete example?

asmarques avatar Nov 02 '21 22:11 asmarques

Hey Paul, that's funny, I'm actually using your template

Oh haha!

You just didn't have any examples working with bignumbers so I went looking for a solution.

You don't need a package like chai-bignumber if you're using my template. Waffle has built-in support for BigNumber matchers.

PaulRBerg avatar Nov 03 '21 09:11 PaulRBerg