UNPKG

weak-dictionary

Version:
68 lines (57 loc) 1.97 kB
var assert = require('assert'), should = require('should'), sinon = require('sinon'), WeaKDictionary = require('../src/index'); describe('Unit', function() { describe('weak-dictionary', function() { describe('construct', function() { it("standard success", function() { // arrange/act var instance = new WeaKDictionary(); // assertact should.exist(instance); }); }); describe('no leaks', function() { it("force delete", function() { // arrange var instance = new WeaKDictionary(); // act var hashKey = { key: "myItem" }; var Clazz = function() { this.items = []; for (var i = 0; i <= 100; i++) this.items.push(1); }; var hashObj = new Clazz(); instance.set(hashKey, hashObj); instance.delete(hashKey); // assert instance.has(hashKey).should.equal(false); }); it("gc delete", function() { // arrange var instance = new WeaKDictionary(); // act var hashKey = { key: "myItem" }; var Clazz = function() { this.items = []; for (var i = 0; i <= 100000; i++) this.items.push(i); }; var hashObj = new Clazz(); instance.set(hashKey, hashObj); delete hashObj; hashObj = null; global.gc(); instance.refresh(); // assertact instance.has(hashKey).should.equal(false); }); }); }); });