UNPKG

inversify

Version:

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

50 lines 1.71 kB
import { __decorate, __metadata } from "tslib"; import { describe, expect, it, vitest } from 'vitest'; import { bindingScopeValues, Container, injectable, preDestroy, } from '../../index.js'; describe('Issue 1416', () => { it('should allow providing default values on optional bindings', async () => { let Test1 = class Test1 { onDestroyMock = vitest.fn(); destroy() { this.onDestroyMock(); } }; __decorate([ preDestroy(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Test1.prototype, "destroy", null); Test1 = __decorate([ injectable() ], Test1); let Test2 = class Test2 { destroy() { } }; Test2 = __decorate([ injectable() ], Test2); let Test3 = class Test3 { destroy() { } }; Test3 = __decorate([ injectable() ], Test3); const container = new Container({ defaultScope: 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.unbindAsync(Test1), container.unbindAsync(Test2), container.unbindAsync(Test3), ]); expect(test1.onDestroyMock).toHaveBeenCalledTimes(1); }); }); //# sourceMappingURL=issue_1416.test.js.map