@unilogin/sdk
Version:
SDK is a JS library, that communicates with relayer. SDK allows managing contract, by creating basic contract-calling messages.
58 lines • 2.34 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var sinon_1 = __importDefault(require("sinon"));
var ReferenceCountedState_1 = require("../../../src/core/states/ReferenceCountedState");
var TestState = /** @class */ (function (_super) {
__extends(TestState, _super);
function TestState() {
var _this = _super.call(this, 0) || this;
_this.onFirstSubscribe = sinon_1.default.spy();
_this.onLastUnsubscribe = sinon_1.default.spy();
return _this;
}
return TestState;
}(ReferenceCountedState_1.ReferenceCountedState));
describe('UNIT: ReferenceCountedState', function () {
var state;
var callback;
beforeEach(function () {
state = new TestState();
callback = sinon_1.default.spy();
});
it('no subscriptions', function () {
state = new TestState();
chai_1.expect(state.get()).to.eq(0);
});
it('1 subscription', function () {
var unsubscribe = state.subscribe(callback);
chai_1.expect(state.onFirstSubscribe).to.have.been.calledOnce;
unsubscribe();
chai_1.expect(state.onLastUnsubscribe).to.have.been.calledOnce;
});
it('2 subscriptions', function () {
var unsubscribe = state.subscribe(callback);
var unsubscribe2 = state.subscribe(callback);
chai_1.expect(state.onFirstSubscribe).to.have.been.calledOnce;
unsubscribe();
unsubscribe2();
chai_1.expect(state.onLastUnsubscribe).to.have.been.calledOnce;
});
});
//# sourceMappingURL=ReferenceCountedState.test.js.map
;