Skip to content

Commit 1e598c5

Browse files
authoredMay 6, 2022
🌂 closeTo actual convert to BN (#724)
1 parent 2ccc395 commit 1e598c5

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed
 

‎.changeset/eighty-squids-knock.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ethereum-waffle/chai": patch
3+
---
4+
5+
BN closeTo actual may be a js number

‎waffle-chai/src/matchers/bigNumber.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function overwriteBigNumberCloseTo(_super: (...args: any[]) => any, chaiUtils: C
101101
BigNumber.from(expected).sub(actual).abs().lte(delta),
102102
`Expected "${expected}" to be within ${delta} of ${actual}`,
103103
`Expected "${expected}" NOT to be within ${delta} of ${actual}`,
104-
`A number between ${actual.sub(delta)} and ${actual.sub(delta)}`,
104+
`A number between ${BigNumber.from(actual).sub(delta)} and ${BigNumber.from(actual).sub(delta)}`,
105105
expected
106106
);
107107
} else {

‎waffle-chai/test/matchers/bigNumber.test.ts

+24-20
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,36 @@ describe('UNIT: BigNumber matchers', () => {
141141

142142
describe('closeTo', () => {
143143
it('.to.be.closeTo', () => {
144-
expect(BigNumber.from(100)).to.be.closeTo(BigNumber.from(101), 10);
145-
expect(BigNumber.from(100)).to.be.closeTo(BigNumber.from(101), BigNumber.from(10));
144+
checkAll(100, 101, (a, b) => expect(a).to.be.closeTo(b, 10));
145+
checkAll(100, 101, (a, b) => expect(a).to.be.closeTo(b, BigNumber.from(10)));
146146
});
147147

148148
it('.not.to.be.closeTo', () => {
149-
expect(BigNumber.from(100)).not.to.be.closeTo(BigNumber.from(111), 10);
150-
expect(BigNumber.from(100)).not.to.be.closeTo(BigNumber.from(111), BigNumber.from(10));
149+
checkAll(100, 111, (a, b) => expect(a).not.to.be.closeTo(b, 10));
150+
checkAll(100, 111, (a, b) => expect(a).not.to.be.closeTo(b, BigNumber.from(10)));
151151
});
152152

153153
it('expect to throw on error', () => {
154-
expect(() => expect(BigNumber.from(100)).to.be.closeTo(BigNumber.from(111), 10)).to.throw(
155-
AssertionError,
156-
'Expected "100" to be within 10 of 111'
157-
);
158-
expect(() => expect(BigNumber.from(100)).to.be.closeTo(BigNumber.from(111), BigNumber.from(10))).to.throw(
159-
AssertionError,
160-
'Expected "100" to be within 10 of 111'
161-
);
162-
expect(() => expect(BigNumber.from(100)).not.to.be.closeTo(BigNumber.from(101), 10)).to.throw(
163-
AssertionError,
164-
'Expected "100" NOT to be within 10 of 101'
165-
);
166-
expect(() => expect(BigNumber.from(100)).not.to.be.closeTo(BigNumber.from(101), BigNumber.from(10))).to.throw(
167-
AssertionError,
168-
'Expected "100" NOT to be within 10 of 101'
169-
);
154+
checkAll(100, 111, (a, b) => {
155+
expect(() => expect(BigNumber.from(a)).to.be.closeTo(BigNumber.from(b), 10)).to.throw(
156+
AssertionError,
157+
'Expected "100" to be within 10 of 111'
158+
);
159+
expect(() => expect(BigNumber.from(a)).to.be.closeTo(BigNumber.from(b), BigNumber.from(10))).to.throw(
160+
AssertionError,
161+
'Expected "100" to be within 10 of 111'
162+
);
163+
});
164+
checkAll(100, 101, (a, b) => {
165+
expect(() => expect(BigNumber.from(a)).not.to.be.closeTo(BigNumber.from(b), 10)).to.throw(
166+
AssertionError,
167+
'Expected "100" NOT to be within 10 of 101'
168+
);
169+
expect(() => expect(BigNumber.from(a)).not.to.be.closeTo(BigNumber.from(b), BigNumber.from(10))).to.throw(
170+
AssertionError,
171+
'Expected "100" NOT to be within 10 of 101'
172+
);
173+
});
170174
});
171175
});
172176
});

0 commit comments

Comments
 (0)
Please sign in to comment.