Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should works, expect doesn't #10

Open
PaulRBerg opened this issue Jul 23, 2019 · 7 comments
Open

should works, expect doesn't #10

PaulRBerg opened this issue Jul 23, 2019 · 7 comments

Comments

@PaulRBerg
Copy link

PaulRBerg commented Jul 23, 2019

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]

@amazingandyyy
Copy link

any updates?
same issue here

@asmarques
Copy link
Owner

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

@colinsteidtmann
Copy link

colinsteidtmann commented Nov 2, 2021

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;

@PaulRBerg
Copy link
Author

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.

@colinsteidtmann
Copy link

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.

@asmarques
Copy link
Owner

@colinsteidtmann can you provide a complete example?

@PaulRBerg
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants