fix(tests): restore matchers
We previously inherited the test matchers from diagram-js. With the diagram-js migration to Mocha, the matchers changed. As a result Jasmine silently discarted a number of test cases on our suite. This restores the old matchers from diagram-js in our project.
This commit is contained in:
parent
788bcf3c48
commit
701bae6c1f
|
@ -1 +1,85 @@
|
|||
module.exports = require('diagram-js/test/Matchers');
|
||||
'use strict';
|
||||
|
||||
/* global jasmine */
|
||||
|
||||
var cloneDeep = require('lodash/lang/cloneDeep'),
|
||||
isEqual = require('lodash/lang/isEqual'),
|
||||
pick = require('lodash/object/pick');
|
||||
|
||||
|
||||
module.exports.addDeepEquals = function() {
|
||||
var jsondiffpatch = require('jsondiffpatch');
|
||||
|
||||
var compare = jsondiffpatch.create({
|
||||
objectHash: function (obj) {
|
||||
return JSON.stringify(obj);
|
||||
}
|
||||
});
|
||||
|
||||
function deepEquals(actual, expected) {
|
||||
var actualClone = cloneDeep(actual);
|
||||
var expectedClone = cloneDeep(expected);
|
||||
|
||||
var result = {
|
||||
pass: isEqual(actualClone, expectedClone)
|
||||
};
|
||||
|
||||
var message;
|
||||
|
||||
if (!result.pass) {
|
||||
message =
|
||||
'Expected elements to equal but got diff\n' +
|
||||
JSON.stringify(compare.diff(actualClone, expectedClone), null, ' ');
|
||||
} else {
|
||||
message = 'Expected elements not to equal';
|
||||
}
|
||||
|
||||
result.message = message;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
jasmine.addMatchers({
|
||||
toDeepEqual: function(util) {
|
||||
return {
|
||||
compare: deepEquals
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.addBBoxMatchers = function() {
|
||||
|
||||
jasmine.addMatchers({
|
||||
|
||||
toFitBBox: function(util) {
|
||||
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
|
||||
var actualBBox = actual.getBBox();
|
||||
|
||||
var pass = actualBBox.x >= expected.x &&
|
||||
actualBBox.y >= expected.y &&
|
||||
actualBBox.width <= expected.width &&
|
||||
actualBBox.x + actualBBox.width <= expected.x + expected.width &&
|
||||
(expected.height ? actualBBox.height <= expected.height : true) &&
|
||||
(expected.height ? actualBBox.y + actualBBox.height <= expected.y + expected.height : true);
|
||||
|
||||
var message = '';
|
||||
|
||||
if (!pass) {
|
||||
message = 'Expected element#' + actual.id + ' with bbox ' +
|
||||
jasmine.pp(pick(actualBBox, ['x', 'y', 'width', 'height'])) + ' to fit ' +
|
||||
jasmine.pp(expected);
|
||||
}
|
||||
|
||||
return {
|
||||
pass: pass,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue