truffle-assertions
Advanced tools
Comparing version 0.8.2 to 0.9.0
28
index.js
const AssertionError = require('assertion-error'); | ||
const isEqual = require('lodash.isequal'); | ||
/* global web3 */ | ||
@@ -154,8 +156,26 @@ | ||
const takeSameKeys = (filterOrObject, obj) => Object.keys(filterOrObject) | ||
.reduce((accumulator, key) => { | ||
if (obj.hasOwnProperty(key)) { | ||
accumulator[key] = obj[key]; | ||
} | ||
return accumulator; | ||
}, {}); | ||
const toFilterFunction = (filterOrObject) => { | ||
if (filterOrObject !== null && typeof filterOrObject === 'object') { | ||
return (obj) => { | ||
const objectToCompare = takeSameKeys(filterOrObject, obj); | ||
return isEqual(filterOrObject, objectToCompare); | ||
}; | ||
} | ||
return filterOrObject; | ||
}; | ||
module.exports = { | ||
eventEmitted: (result, eventType, filter, message) => { | ||
assertEventEmittedFromTxResult(result, eventType, filter, message); | ||
eventEmitted: (result, eventType, filterOrObject, message) => { | ||
assertEventEmittedFromTxResult(result, eventType, toFilterFunction(filterOrObject), message); | ||
}, | ||
eventNotEmitted: (result, eventType, filter, message) => { | ||
assertEventNotEmittedFromTxResult(result, eventType, filter, message); | ||
eventNotEmitted: (result, eventType, filterOrObject, message) => { | ||
assertEventNotEmittedFromTxResult(result, eventType, toFilterFunction(filterOrObject), message); | ||
}, | ||
@@ -162,0 +182,0 @@ prettyPrintEmittedEvents: (result, indentationSize) => { |
{ | ||
"name": "truffle-assertions", | ||
"version": "0.8.2", | ||
"version": "0.9.0", | ||
"description": "Additional assertions and utilities for testing Ethereum smart contracts in Truffle unit tests", | ||
@@ -12,3 +12,4 @@ "main": "index.js", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
"lint": "eslint index.js test/*.js" | ||
"lint": "eslint index.js test/*.js", | ||
"lint-fix": "eslint --fix index.js test/*.js" | ||
}, | ||
@@ -38,3 +39,4 @@ "nyc": { | ||
"dependencies": { | ||
"assertion-error": "^1.1.0" | ||
"assertion-error": "^1.1.0", | ||
"lodash.isequal": "^4.5.0" | ||
}, | ||
@@ -41,0 +43,0 @@ "devDependencies": { |
@@ -43,2 +43,8 @@ # truffle-assertions | ||
Alternatively, a filter object can be passed in place of a function. If an object is passed, this object will be matched against the event's arguments. This object does not need to include all the event's arguments; only the included ones will be used in the comparison. | ||
```javascript | ||
truffleAssert.eventEmitted(result, 'TestEvent', { param1: 10, param2: 20 }); | ||
``` | ||
When the `filter` parameter is omitted or set to null, the assertion checks just for event type: | ||
@@ -76,2 +82,8 @@ | ||
Alternatively, a filter object can be passed in place of a function. If an object is passed, this object will be matched against the event's arguments. This object does not need to include all the event's arguments; only the included ones will be used in the comparison. | ||
```javascript | ||
truffleAssert.eventNotEmitted(result, 'TestEvent', { param1: 10, param2: 20 }); | ||
``` | ||
When the `filter` parameter is omitted or set to null, the assertion checks just for event type: | ||
@@ -158,3 +170,3 @@ | ||
The different error types are defined as follows: | ||
``` | ||
```javascript | ||
ErrorType = { | ||
@@ -222,5 +234,5 @@ REVERT: "revert", | ||
- [truffle-events](https://github.com/zulhfreelancer/truffle-events) — 3rd party add-on to this project with 'deep events' support. You can test emitted events in other contracts, provided they are in the same transaction i.e. event A (contract A) and event B (contract B) are produced in the same transaction. | ||
* [truffle-events](https://github.com/zulhfreelancer/truffle-events) — 3rd party add-on to this project with 'deep events' support. You can test emitted events in other contracts, provided they are in the same transaction i.e. event A (contract A) and event B (contract B) are produced in the same transaction. | ||
## Donations | ||
If you use this library inside your own projects and you would like to support its development, you can donate Ξ to `0x6775f0Ee4E63983501DBE7b0385bF84DBd36D69B`. |
19206
175
235
2
+ Addedlodash.isequal@^4.5.0
+ Addedlodash.isequal@4.5.0(transitive)