2020-01-28 13:08:03 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var keys = require('object-keys');
|
|
|
|
var forEach = require('foreach');
|
2020-03-07 11:45:40 +08:00
|
|
|
var indexOf = require('array.prototype.indexof');
|
2020-01-28 13:08:03 +08:00
|
|
|
|
|
|
|
module.exports = function diffOperations(actual, expected, expectedMissing) {
|
|
|
|
var actualKeys = keys(actual);
|
|
|
|
var expectedKeys = keys(expected);
|
|
|
|
|
|
|
|
var extra = [];
|
|
|
|
var missing = [];
|
|
|
|
forEach(actualKeys, function (op) {
|
|
|
|
if (!(op in expected)) {
|
|
|
|
extra.push(op);
|
2020-03-07 11:45:40 +08:00
|
|
|
} else if (indexOf(expectedMissing, op) !== -1) {
|
2020-01-28 13:08:03 +08:00
|
|
|
extra.push(op);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
forEach(expectedKeys, function (op) {
|
2020-03-07 11:45:40 +08:00
|
|
|
if (typeof actual[op] !== 'function' && indexOf(expectedMissing, op) === -1) {
|
2020-01-28 13:08:03 +08:00
|
|
|
missing.push(op);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return { missing: missing, extra: extra };
|
|
|
|
};
|