The error states that 'push is not a function', this is because we encountered compareOptions.ignoreRectangles to be the number 1, rather than an array.
The problem lies in the fact that .push is used improperly. From the MDN docs:
The push() method adds one or more elements to the end of an array and returns the new length of the array.
The push method gives back the new array length instead of the array itself.
Replacing push with concat fixes this bug.
The following code demonstrates the bug:
let ignoreRectangles = [];
const compareOptions = {}
function doIt() {
compareOptions.ignoreRectangles = 'ignoreRectangles' in compareOptions ? compareOptions.ignoreRectangles.push(ignoreRectangles) : ignoreRectangles;
console.log(compareOptions);
}
doIt();
doIt();
In our testing setup, we encounter an error when running multiple tests with the same options object.
We get an error on this line: https://github.com/wswebcreation/protractor-image-comparison/blob/6fa7b194b1bb1d6ba37946af51b4252170185ed4/index.js#L354
The error states that 'push is not a function', this is because we encountered compareOptions.ignoreRectangles to be the number 1, rather than an array.
The problem lies in the fact that
.push
is used improperly. From the MDN docs:The push method gives back the new array length instead of the array itself.
Replacing push with concat fixes this bug.
The following code demonstrates the bug: