UNPKG

inversify

Version:

A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.

52 lines 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const vitest_1 = require("vitest"); const __1 = require("../.."); (0, vitest_1.describe)('Issue 1416', () => { (0, vitest_1.it)('should allow providing default values on optional bindings', async () => { let Test1 = class Test1 { onDestroyMock = vitest_1.vitest.fn(); destroy() { this.onDestroyMock(); } }; tslib_1.__decorate([ (0, __1.preDestroy)(), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", []), tslib_1.__metadata("design:returntype", void 0) ], Test1.prototype, "destroy", null); Test1 = tslib_1.__decorate([ (0, __1.injectable)() ], Test1); let Test2 = class Test2 { destroy() { } }; Test2 = tslib_1.__decorate([ (0, __1.injectable)() ], Test2); let Test3 = class Test3 { destroy() { } }; Test3 = tslib_1.__decorate([ (0, __1.injectable)() ], Test3); const container = new __1.Container({ defaultScope: __1.bindingScopeValues.Singleton, }); container.bind(Test1).toSelf(); container.bind(Test2).toService(Test1); container.bind(Test3).toService(Test1); const test1 = container.get(Test1); container.get(Test2); container.get(Test3); await Promise.all([ container.unbind(Test1), container.unbind(Test2), container.unbind(Test3), ]); (0, vitest_1.expect)(test1.onDestroyMock).toHaveBeenCalledTimes(1); }); }); //# sourceMappingURL=issue_1416.test.js.map