Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 2707b7e

Browse files
committed
Adding a test suite for WeakMap.
1 parent a0947a9 commit 2707b7e

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tests/index.html

+37-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
Use of this source code is governed by a BSD-style
55
license that can be found in the LICENSE file.
66
-->
7-
<title>PointerEvent tests</title>
7+
<title>WeakMap tests</title>
88
<meta charset="UTF8">
99
<!-- Mocha -->
1010
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
1111
<script src="../node_modules/mocha/mocha.js"></script>
1212
<!-- Chai -->
1313
<script src="../node_modules/chai/chai.js"></script>
14-
<!-- PointerEvents -->
14+
<!-- WeakMap -->
1515
<script src="../weakmap.js"></script>
1616
<!-- Test Setup -->
1717
<div id="mocha"></div>
@@ -22,6 +22,41 @@
2222
});
2323
</script>
2424
<!-- Tests -->
25+
<script>
26+
suite('WeakMap', function() {
27+
28+
var assert = chai.assert;
29+
30+
test('WeakMap has get and set functions', function() {
31+
assert.isDefined(WeakMap.prototype.get);
32+
assert.isDefined(WeakMap.prototype.set);
33+
});
34+
35+
test('WeakMap\'s get and set perform as expected', function() {
36+
var wm = new WeakMap();
37+
38+
var o1 = {};
39+
var o2 = function(){};
40+
var o3 = window;
41+
42+
wm.set(o1, 37);
43+
wm.set(o2, 'aoeui');
44+
45+
assert.equal(wm.get(o1), 37);
46+
assert.equal(wm.get(o2), 'aoeui');
47+
48+
wm.set(o1, o2);
49+
wm.set(o3, undefined);
50+
51+
assert.deepEqual(wm.get(o1), o2);
52+
// `wm.get({})` should return undefined, because there is no value for
53+
// the object on wm
54+
assert.equal(wm.get({}), undefined);
55+
// `wm.get(o3)` should return undefined, because that is the set value
56+
assert.equal(wm.get(o3), undefined);
57+
});
58+
});
59+
</script>
2560
<!-- Run Mocha -->
2661
<script>
2762
mocha.run();

0 commit comments

Comments
 (0)