|
4 | 4 | Use of this source code is governed by a BSD-style
|
5 | 5 | license that can be found in the LICENSE file.
|
6 | 6 | -->
|
7 |
| -<title>PointerEvent tests</title> |
| 7 | +<title>WeakMap tests</title> |
8 | 8 | <meta charset="UTF8">
|
9 | 9 | <!-- Mocha -->
|
10 | 10 | <link rel="stylesheet" href="../node_modules/mocha/mocha.css">
|
11 | 11 | <script src="../node_modules/mocha/mocha.js"></script>
|
12 | 12 | <!-- Chai -->
|
13 | 13 | <script src="../node_modules/chai/chai.js"></script>
|
14 |
| -<!-- PointerEvents --> |
| 14 | +<!-- WeakMap --> |
15 | 15 | <script src="../weakmap.js"></script>
|
16 | 16 | <!-- Test Setup -->
|
17 | 17 | <div id="mocha"></div>
|
|
22 | 22 | });
|
23 | 23 | </script>
|
24 | 24 | <!-- 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> |
25 | 60 | <!-- Run Mocha -->
|
26 | 61 | <script>
|
27 | 62 | mocha.run();
|
|
0 commit comments