question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Events emitted during test reports events emitted during suite

See original GitHub issue

Consider following contract:

contract Emitter {
    event Called();
    function emit() {
        Called();
    }
}

And tests:

contract('Emitter', function(accounts) {
  it('should emit Called event and fail (shows 1 emitted)', function(done) {
    var emitter = Emitter.deployed();
    emitter.emit().then(function() {
      assert.isTrue(false);
    }).then(done).catch(done);
  });
  it('should emit Called event', function(done) {
    var emitter = Emitter.deployed();
    emitter.emit().then(function() {
      done();
    }).catch(done);
  });
  it('should emit Called event 2', function(done) {
    var emitter = Emitter.deployed();
    emitter.emit().then(function() {
      done();
    }).catch(done);
  });
  it('should emit Called event and fail 2 (shows 3 emitted)', function(done) {
    var emitter = Emitter.deployed();
    emitter.emit().then(function() {
      assert.isTrue(false);      
    }).then(done).catch(done);
  });
  it('should emit Called event and fail 3 (shows 1 emitted)', function(done) {
    var emitter = Emitter.deployed();
    emitter.emit().then(function() {
      assert.isTrue(false);      
    }).then(done).catch(done);
  });
});

Output:

Contract: Emitter
    1) should emit Called event and fail (shows 1 emitted)
    Events emitted during test:
    ---------------------------
    Called()
    ---------------------------
    ✓ should emit Called event
    ✓ should emit Called event 2 (48ms)
    2) should emit Called event and fail 2 (shows 3 emitted)
    Events emitted during test:
    ---------------------------
    Called()
    Called()
    Called()
    ---------------------------
    3) should emit Called event and fail 3 (shows 1 emitted)
    Events emitted during test:
    ---------------------------
    Called()
    ---------------------------
  2 passing (8s)
  3 failing

As you can see, when 3rd test fails, it reports the events emitted between last failed test (exclusive) and current test (inclusive).

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
OTTTOcommented, Mar 21, 2018

@cbruguera Yes, I believe this should be an option; potentially a set option in the mocha config.

2reactions
cbrugueracommented, Oct 1, 2017

@tcoulter Hello, is there any way to display events emitted in all cases (even for succeeded tests)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to hide "Events emitted during test" in truffle test?
You can search in your node_modules for the lines that log the events. In my case, I used VSCode search ( ctrl +...
Read more >
Test ethereum Event Logs with truffle - Stack Overflow
@user3262670 I do not see any check for events in test at all. + all test cases are named "should emit Error event...
Read more >
What are Events in Solidity? - GeeksforGeeks
An event is an inheritable member of the contract, which stores the arguments passed in the transaction logs when emitted.
Read more >
Truffle Event System
Another common label, "fail" , is used to indicate the failure of a certain event. When the event "compile:start" is emitted, it means...
Read more >
Everything You Ever Wanted to Know About Events and Logs ...
They're making use of the Transfer event that is created in the screenshot above. Basically, the emit lines say that anytime these functions ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found