Skip to content

Commit 1dbc6dc

Browse files
committed
implements nested tests
1 parent 0603eb9 commit 1dbc6dc

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

packages/hardhat-chai-matchers/test/events.ts

+42-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ describe(".to.emit (contract events)", () => {
6464
});
6565

6666
it("Should detect events without arguments", async function () {
67-
await expect(contract.emitWithoutArgs())
68-
.to.emit(contract, "WithoutArgs")
69-
.withArgs();
67+
await expect(contract.emitWithoutArgs()).to.emit(contract, "WithoutArgs");
7068
});
7169

7270
it("Should fail when expecting an event that wasn't emitted", async function () {
@@ -115,6 +113,12 @@ describe(".to.emit (contract events)", () => {
115113
);
116114
});
117115

116+
it("Should verify zero arguments", async function () {
117+
await expect(contract.emitWithoutArgs())
118+
.to.emit(contract, "WithoutArgs")
119+
.withArgs();
120+
});
121+
118122
describe("with a uint argument", function () {
119123
it("Should match the argument", async function () {
120124
await expect(contract.emitUint(1))
@@ -391,6 +395,41 @@ describe(".to.emit (contract events)", () => {
391395
);
392396
});
393397

398+
describe("nested predicate", async function () {
399+
it("Should succeed when predicate passes", async function () {
400+
await expect(contract.emitUintArray(1, 2))
401+
.to.emit(contract, "WithUintArray")
402+
.withArgs([anyValue, 2]);
403+
});
404+
405+
it("Should fail when predicate returns false", async function () {
406+
await expect(
407+
expect(contract.emitUintArray(1, 2))
408+
.to.emit(contract, "WithUintArray")
409+
.withArgs([() => false, 4])
410+
).to.be.eventually.rejectedWith(
411+
AssertionError,
412+
`Error in "WithUintArray" event: Error in the 1st argument assertion: Error in the 1st argument assertion: The predicate did not return true`
413+
);
414+
});
415+
416+
it("Should fail when predicate reverts", async function () {
417+
await expect(
418+
expect(contract.emitUintArray(1, 2))
419+
.to.emit(contract, "WithUintArray")
420+
.withArgs([
421+
() => {
422+
throw new Error("user error");
423+
},
424+
4,
425+
])
426+
).to.be.eventually.rejectedWith(
427+
AssertionError,
428+
`Error in "WithUintArray" event: Error in the 1st argument assertion: Error in the 1st argument assertion: The predicate threw when called: user error`
429+
);
430+
});
431+
});
432+
394433
describe("arrays different length", function () {
395434
it("Should fail when the array is shorter", async function () {
396435
await expect(

0 commit comments

Comments
 (0)