You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
627 B

4 years ago
  1. 'use strict';
  2. var keys = require('object-keys');
  3. var forEach = require('foreach');
  4. module.exports = function diffOperations(actual, expected, expectedMissing) {
  5. var actualKeys = keys(actual);
  6. var expectedKeys = keys(expected);
  7. var extra = [];
  8. var missing = [];
  9. forEach(actualKeys, function (op) {
  10. if (!(op in expected)) {
  11. extra.push(op);
  12. } else if (expectedMissing.indexOf(op) !== -1) {
  13. extra.push(op);
  14. }
  15. });
  16. forEach(expectedKeys, function (op) {
  17. if (typeof actual[op] !== 'function' && expectedMissing.indexOf(op) === -1) {
  18. missing.push(op);
  19. }
  20. });
  21. return { missing: missing, extra: extra };
  22. };