Version 1
[yaffs-website] / node_modules / es5-shim / tests / helpers / h-matchers.js
1 /* global beforeEach, expect */
2
3 var has = Object.prototype.hasOwnProperty;
4 var getKeys = function (o) {
5     'use strict';
6
7     var key;
8     var a = [];
9     for (key in o) {
10         if (has.call(o, key)) {
11             a.push(key);
12         }
13     }
14     return a;
15 };
16
17 beforeEach(function () {
18     'use strict';
19
20     this.addMatchers({
21         toExactlyMatch: function (expected) {
22             var a1, a2, l, i, key;
23             var actual = this.actual;
24
25             a1 = getKeys(actual);
26             a2 = getKeys(expected);
27
28             l = a1.length;
29             if (l !== a2.length) {
30                 return false;
31             }
32             for (i = 0; i < l; i++) {
33                 key = a1[i];
34                 expect(key).toEqual(a2[i]);
35                 expect(actual[key]).toEqual(expected[key]);
36             }
37
38             return true;
39         }
40     });
41 });