Events emitted during test reports events emitted during suite
See original GitHub issueConsider 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:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@cbruguera Yes, I believe this should be an option; potentially a set option in the mocha config.
@tcoulter Hello, is there any way to display events emitted in all cases (even for succeeded tests)?