reign
Version:
A persistent, typed-objects implementation.
60 lines (46 loc) • 1.97 kB
JavaScript
;
var _ = require("./");
var _backing = require("backing");
var _backing2 = _interopRequireDefault(_backing);
var _symbols = require("./symbols");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; }
describeRealm('Realm', function (options) {
var realm = void 0;
var other = void 0;
var T = void 0;
before(function () {
realm = options.realm;
T = realm.T;
});
it('should set a key / value', function () {
realm.set('foo', 'bar');
});
it('should get a key / value', function () {
realm.get('foo').should.equal('bar');
});
it('should load another copy of the realm', _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
other = new _.Realm(new _backing2.default(options.backingOptions));
_context.next = 3;
return other.init();
case 3:
case "end":
return _context.stop();
}
}
}, _callee, this);
})));
it('should get the key / value', function () {
other.get('foo').should.equal('bar');
});
it('should share key / values across realm instances', function () {
other.set('foo', 'baz');
realm.set('obj', { a: 1, b: 2, c: 3 });
realm.get('foo').should.equal('baz');
other.get('obj').should.eql({ a: 1, b: 2, c: 3 });
});
});