Skip to content

Commit

Permalink
Add event emitted matcher negation support (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruch authored and marekkirejczyk committed Jan 15, 2020
1 parent 68e9c8a commit 7c4d835
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 4 additions & 7 deletions waffle-chai/src/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@ export const waffleChai = (chai: any, chaiUtils: any) => {

const {topic} = eventDescription;
this.logs = filterLogsWithTopics(receipt.logs, topic);
if (this.logs.length < 1) {
this.assert(false,
`Expected event "${eventName}" to emitted, but wasn't`,
`Expected event "${eventName}" NOT to emitted, but it was`,
eventName,
'');
}
this.assert(this.logs.length > 0,
`Expected event "${eventName}" to be emitted, but it wasn't`,
`Expected event "${eventName}" NOT to be emitted, but it was`
);
});
this.then = derivedPromise.then.bind(derivedPromise);
this.catch = derivedPromise.catch.bind(derivedPromise);
Expand Down
14 changes: 12 additions & 2 deletions waffle-chai/test/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('INTEGRATION: Events', () => {
it('Emit one: fail', async () => {
await expect(
expect(events.emitOne()).to.emit(events, 'Two')
).to.be.eventually.rejectedWith(AssertionError, 'Expected event "Two" to emitted, but wasn\'t');
).to.be.eventually.rejectedWith(AssertionError, 'Expected event "Two" to be emitted, but it wasn\'t');
});

it('Emit two: success', async () => {
Expand All @@ -29,7 +29,17 @@ describe('INTEGRATION: Events', () => {
it('Emit two: fail', async () => {
await expect(
expect(events.emitTwo()).to.emit(events, 'One')
).to.be.eventually.rejectedWith(AssertionError, 'Expected event "One" to emitted, but wasn\'t');
).to.be.eventually.rejectedWith(AssertionError, 'Expected event "One" to be emitted, but it wasn\'t');
});

it('Do not emit one: fail', async () => {
await expect(
expect(events.emitOne()).to.not.emit(events, 'One')
).to.be.eventually.rejectedWith(AssertionError, 'Expected event "One" NOT to be emitted, but it was');
});

it('Do not emit two: success', async () => {
await expect(events.emitTwo()).to.not.emit(events, 'One');
});

it('Emit unexistent event: fail', async () => {
Expand Down

0 comments on commit 7c4d835

Please sign in to comment.