-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest.js
40 lines (32 loc) · 1.44 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { expect } = require("chai");
describe("EventEmitter", function () {
it("Should emit MyEvent", async function () {
const EventEmitter = await ethers.getContractFactory("EventEmitter");
const eventEmitter = await EventEmitter.deploy();
await eventEmitter.deployed();
await expect(eventEmitter.emitMyEvent()).to.emit(eventEmitter, "MyEvent");
});
it("Should emit MyEventWithData", async function () {
const EventEmitter = await ethers.getContractFactory("EventEmitter");
const eventEmitter = await EventEmitter.deploy();
await eventEmitter.deployed();
await expect(eventEmitter.emitMyEventWithData(42, "foo"))
.to.emit(eventEmitter, "MyEventWithData")
.withArgs(42, "foo");
});
it("Should emit both events", async function () {
const EventEmitter = await ethers.getContractFactory("EventEmitter");
const eventEmitter = await EventEmitter.deploy();
await eventEmitter.deployed();
await expect(eventEmitter.emitBothEvents(42, "foo"))
.to.emit(eventEmitter, "MyEventWithData")
.withArgs(42, "foo")
.and.to.emit(eventEmitter, "MyEvent");
});
it("Should emit event in the constructor", async function () {
const EventEmitter = await ethers.getContractFactory("EventEmitter");
const eventEmitter = await EventEmitter.deploy();
await eventEmitter.deployed();
await expect(eventEmitter.deployTransaction).to.emit(eventEmitter, "ConstructorEvent");
});
});