h-matchers.js 843 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var has = Object.prototype.hasOwnProperty;
  2. var getKeys = function (o) {
  3. 'use strict';
  4. var key;
  5. var a = [];
  6. for (key in o) {
  7. if (has.call(o, key)) {
  8. a.push(key);
  9. }
  10. }
  11. a.sort();
  12. return a;
  13. };
  14. beforeEach(function () {
  15. 'use strict';
  16. this.addMatchers({
  17. toExactlyMatch: function (expected) {
  18. var a1, a2, l, i, key;
  19. var actual = this.actual;
  20. a1 = getKeys(actual);
  21. a2 = getKeys(expected);
  22. l = a1.length;
  23. if (l !== a2.length) {
  24. return false;
  25. }
  26. for (i = 0; i < l; i++) {
  27. key = a1[i];
  28. expect(key).toEqual(a2[i]);
  29. expect(actual[key]).toEqual(expected[key]);
  30. }
  31. return true;
  32. }
  33. });
  34. });