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

Commit

Permalink
Adding a test suite for WeakMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
markfinger committed Mar 30, 2014
1 parent a0947a9 commit 2707b7e
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<title>PointerEvent tests</title>
<title>WeakMap tests</title>
<meta charset="UTF8">
<!-- Mocha -->
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<script src="../node_modules/mocha/mocha.js"></script>
<!-- Chai -->
<script src="../node_modules/chai/chai.js"></script>
<!-- PointerEvents -->
<!-- WeakMap -->
<script src="../weakmap.js"></script>
<!-- Test Setup -->
<div id="mocha"></div>
Expand All @@ -22,6 +22,41 @@
});
</script>
<!-- Tests -->
<script>
suite('WeakMap', function() {

var assert = chai.assert;

test('WeakMap has get and set functions', function() {
assert.isDefined(WeakMap.prototype.get);
assert.isDefined(WeakMap.prototype.set);
});

test('WeakMap\'s get and set perform as expected', function() {
var wm = new WeakMap();

var o1 = {};
var o2 = function(){};
var o3 = window;

wm.set(o1, 37);
wm.set(o2, 'aoeui');

assert.equal(wm.get(o1), 37);
assert.equal(wm.get(o2), 'aoeui');

wm.set(o1, o2);
wm.set(o3, undefined);

assert.deepEqual(wm.get(o1), o2);
// `wm.get({})` should return undefined, because there is no value for
// the object on wm
assert.equal(wm.get({}), undefined);
// `wm.get(o3)` should return undefined, because that is the set value
assert.equal(wm.get(o3), undefined);
});
});
</script>
<!-- Run Mocha -->
<script>
mocha.run();
Expand Down

0 comments on commit 2707b7e

Please sign in to comment.