UNPKG

area51

Version:

Experimental prototypes of alien things built in JavaScript. The bits may end up living in a different package.

62 lines (52 loc) 1.71 kB
var assert = require("assert"); var Symbol = require("../../lib/es6/symbol"); module.exports = { "Symbol": { "create symbol": function(){ var local = Symbol(); assert.ok(local != null, "symbol must not be null"); assert.ok(local instanceof Symbol, "symbol must be type Symbol"); }, "Symbol.for - returns global symbol": function() { var global = Symbol.for("desc"); var g2 = Symbol.for("desc"); assert.ok(global !== null, "global is not null"); assert.equal(global, g2); }, "Symbol.forKey - returns description": function() { var global = Symbol.for("desc"); var key = Symbol.keyFor(global); assert.equal("desc", key); var local = Symbol(); key = Symbol.keyFor(local); assert.equal(undefined, key); }, "local symbols create new symbol": function() { var l1 = Symbol(); var l2 = Symbol(); assert.notEqual(l1, l2); }, "local symbols are not global": function() { var l1 = Symbol("desc"); var g1 = Symbol.for("desc"); assert.notEqual(l1, g1, "l1 is not equal to g1"); }, "object property use case": function() { var g1 = Symbol.for("desc"); var obj = {}; obj[g1] = "value"; assert.equal("value", obj[g1]); assert.equal(undefined, obj["g1"]); assert.equal(undefined, obj["desc"]); var results = Object.getOwnPropertySymbols(obj); assert.ok(Array.isArray(results)); assert.equal(g1, results[0]); // verify symbol properties are not enumerable. var failures = []; for(var prop in obj) { failures.push(prop); } assert.equal(0, failures.length, "symbol properties are not enumerable"); } } };