Sha256: e93bc51330a4be459c2acd35ad6b8bcbdb08c306e6dd68ed7ebcecdac8227339

Contents?: true

Size: 1.78 KB

Versions: 24

Compression:

Stored size: 1.78 KB

Contents

var assert = require("assert");
var makeAccessor = require("../private").makeAccessor;
var acc1 = makeAccessor();
var obj = {};
var hasOwn = obj.hasOwnProperty;

acc1(obj).foo = 42;
assert.deepEqual(obj, {});
assert.deepEqual(acc1(obj), { foo: 42 });
assert.deepEqual(acc1(acc1(obj)), {});
assert.deepEqual(acc1(obj), { foo: 42 });
assert.deepEqual(Object.keys(acc1(obj)), ["foo"]);
assert.strictEqual(Object.getOwnPropertyNames(acc1(obj)).length, 1);
assert.strictEqual(Object.getOwnPropertyNames(acc1(acc1(obj))).length, 0);
acc1(obj).bar = "baz";
assert.deepEqual(acc1(obj), { foo: 42, bar: "baz" });
delete acc1(obj).foo;
assert.deepEqual(acc1(obj), { bar: "baz" });

try {
  acc1(42);
  throw new Error("threw wrong error");
} catch (err) {
  assert.ok(err);
}

var acc2 = makeAccessor();
assert.notStrictEqual(acc1, acc2);
assert.notStrictEqual(acc1(obj), acc2(obj));
assert.deepEqual(acc2(obj), {});
assert.strictEqual(Object.getOwnPropertyNames(obj).length, 0);
assert.strictEqual(Object.keys(obj).length, 0);
acc2(obj).bar = "asdf";
assert.deepEqual(acc2(obj), { bar: "asdf" });

acc2.forget(obj);
acc2(obj).bar = "asdf";
var oldSecret = acc2(obj);
assert.strictEqual(oldSecret.bar, "asdf");
acc2.forget(obj);
var newSecret = acc2(obj);
assert.notStrictEqual(oldSecret, newSecret);
assert.ok(hasOwn.call(oldSecret, "bar"));
assert.ok(!hasOwn.call(newSecret, "bar"));
newSecret.bar = "zxcv";
assert.strictEqual(oldSecret.bar, "asdf");
assert.strictEqual(acc2(obj).bar, "zxcv");

function creatorFn(object) {
  return { self: object };
}

var acc3 = makeAccessor(creatorFn);

acc3(obj).xxx = "yyy";
assert.deepEqual(acc3(obj), {
  self: obj,
  xxx: "yyy"
});

acc3.forget(obj);
assert.deepEqual(acc3(obj), {
  self: obj
});

var green = "\033[32m";
var reset = "\033[0m";
console.log(green + "ALL PASS" + reset);

Version data entries

24 entries across 22 versions & 6 rubygems

Version Path
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/private/test/run.js
brwy_rails-0.0.6 test/dummy/node_modules/private/test/run.js
brwy_rails-0.0.5 test/dummy/node_modules/private/test/run.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/private/test/run.js
babel-schmooze-sprockets-0.1.3 node_modules/private/test/run.js
babel-schmooze-sprockets-0.1.2 node_modules/private/test/run.js
babel-schmooze-sprockets-0.1.1 node_modules/private/test/run.js
babel-schmooze-sprockets-0.1.0 node_modules/private/test/run.js
brwy_rails-0.0.4 test/dummy/node_modules/private/test/run.js
brwy_rails-0.0.3 test/dummy/node_modules/private/test/run.js
brwy_rails-0.0.2 test/dummy/node_modules/private/test/run.js
brwy_rails-0.0.1 test/dummy/node_modules/private/test/run.js
babel-schmooze-sprockets-0.1.0.alpha.3 node_modules/private/test/run.js
babel-schmooze-sprockets-0.1.0.alpha.2 node_modules/private/test/run.js
es6_tilt-0.1.2 test/dummy/node_modules/private/test/run.js
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/private/test/run.js
es6_tilt-0.1.1 test/dummy/node_modules/private/test/run.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/private/test/run.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/private/test/run.js
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/private/test/run.js