playable
Version:
Video player based on HTML5Video
114 lines • 6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var chai_1 = require("chai");
var sinon = (0, tslib_1.__importStar)(require("sinon"));
var createContainer_1 = (0, tslib_1.__importDefault)(require("./createContainer"));
var registrations_1 = require("./registrations");
describe('container created by createContainer', function () {
var container;
beforeEach(function () {
container = (0, createContainer_1.default)();
});
it('should have method for registering and resolving modules', function () {
var valueRegistration = (0, registrations_1.asValue)(10);
container.register('value', valueRegistration);
sinon.spy(valueRegistration, 'resolve');
container.resolve('value');
(0, chai_1.expect)(valueRegistration.resolve.called).to.be.equal(true);
var classARegistration = (0, registrations_1.asClass)(/** @class */ (function () {
function A() {
}
return A;
}()));
container.register('classA', classARegistration);
sinon.spy(classARegistration, 'resolve');
container.resolve('classA');
(0, chai_1.expect)(classARegistration.resolve.called).to.be.equal(true);
var funcRegistration = (0, registrations_1.asFunction)(function () { });
container.register('func', funcRegistration);
sinon.spy(funcRegistration, 'resolve');
container.resolve('func');
(0, chai_1.expect)(funcRegistration.resolve.called).to.be.equal(true);
});
it('resolve should react on transient lifetime', function () {
var obj = {};
var transientFuncRegistration = (0, registrations_1.asFunction)(function () { return obj; }).transient();
sinon.spy(transientFuncRegistration, 'resolve');
container.register('func', transientFuncRegistration);
container.resolve('func');
container.resolve('func');
(0, chai_1.expect)(transientFuncRegistration.resolve.calledTwice).to.be.true;
var singletonFuncRegistration = (0, registrations_1.asFunction)(function () { return obj; }).singleton();
sinon.spy(singletonFuncRegistration, 'resolve');
container.register('func2', singletonFuncRegistration);
container.resolve('func2');
container.resolve('func2');
(0, chai_1.expect)(singletonFuncRegistration.resolve.calledOnce).to.be.true;
var scopedFuncRegistration = (0, registrations_1.asFunction)(function () { return obj; }).scoped();
sinon.spy(scopedFuncRegistration, 'resolve');
container.register('func3', scopedFuncRegistration);
container.resolve('func3');
container.resolve('func3');
(0, chai_1.expect)(scopedFuncRegistration.resolve.calledOnce).to.be.true;
var scope = container.createScope();
scope.register('func4', scopedFuncRegistration);
(0, chai_1.expect)(scope.resolve('func3')).to.be.equal(obj);
(0, chai_1.expect)(scopedFuncRegistration.resolve.calledOnce).to.be.true;
(0, chai_1.expect)(function () { return container.resolve('func4'); }).to.throw();
var unknownFuncRegistration = (0, registrations_1.asFunction)(function () { return obj; }).setLifetime('testtest');
container.register('func5', unknownFuncRegistration);
(0, chai_1.expect)(function () { return container.resolve('func5'); }).to.throw();
});
it('resolve should react on singleton lifetime', function () {
var obj = {};
var singletonFuncRegistration = (0, registrations_1.asFunction)(function () { return obj; }).singleton();
sinon.spy(singletonFuncRegistration, 'resolve');
container.register('func2', singletonFuncRegistration);
container.resolve('func2');
container.resolve('func2');
(0, chai_1.expect)(singletonFuncRegistration.resolve.calledOnce).to.be.true;
});
it('resolve should react on scoped lifetime', function () {
var obj = {};
var scopedFuncRegistration = (0, registrations_1.asFunction)(function () { return obj; }).scoped();
sinon.spy(scopedFuncRegistration, 'resolve');
container.register('func3', scopedFuncRegistration);
container.resolve('func3');
container.resolve('func3');
(0, chai_1.expect)(scopedFuncRegistration.resolve.calledOnce).to.be.true;
var scope = container.createScope();
scope.register('func4', scopedFuncRegistration);
(0, chai_1.expect)(scope.resolve('func3')).to.be.equal(obj);
(0, chai_1.expect)(scopedFuncRegistration.resolve.calledOnce).to.be.true;
(0, chai_1.expect)(function () { return container.resolve('func4'); }).to.throw();
});
it('resolve should react on unknown lifetime', function () {
var obj = {};
var unknownFuncRegistration = (0, registrations_1.asFunction)(function () { return obj; }).setLifetime('testtest');
container.register('func5', unknownFuncRegistration);
(0, chai_1.expect)(function () { return container.resolve('func5'); }).to.throw();
});
it('should throw error on duplication of id', function () {
var _a, _b;
container.registerClass('name', (_a = /** @class */ (function () {
function A() {
}
return A;
}()),
_a.dependencies = ['name2'],
_a));
container.registerClass('name2', (_b = /** @class */ (function () {
function B() {
}
return B;
}()),
_b.dependencies = ['name'],
_b));
(0, chai_1.expect)(function () { return container.resolve('name'); }).to.throw();
});
it('should throw error if trying to resolve not registered module', function () {
(0, chai_1.expect)(function () { return container.resolve('name'); }).to.throw();
});
});
//# sourceMappingURL=createContainer.spec.js.map