UNPKG

inversify

Version:

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

77 lines 2.93 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; import { describe, expect, it } from 'vitest'; import { Container, inject, injectable, optional, } from '../../index.js'; describe('Issue 928', () => { it('should inject the right instances', () => { let injectedA; let injectedB; let injectedC; // some dependencies let DepA = class DepA { a = 1; }; DepA = __decorate([ injectable() ], DepA); let DepB = class DepB { b = 1; }; DepB = __decorate([ injectable() ], DepB); let DepC = class DepC { c = 1; }; DepC = __decorate([ injectable() ], DepC); let AbstractCls = class AbstractCls { constructor(a, b = { b: 0 }) { injectedA = a; injectedB = b; } }; AbstractCls = __decorate([ injectable(), __param(0, inject(DepA)), __param(1, inject(DepB)), __param(1, optional()), __metadata("design:paramtypes", [DepA, DepB]) ], AbstractCls); let Cls = class Cls extends AbstractCls { constructor(c, b = { b: 0 }, a) { super(a, b); injectedC = c; } }; Cls = __decorate([ injectable(), __param(0, inject(DepC)), __param(1, inject(DepB)), __param(1, optional()), __param(2, inject(DepA)), __metadata("design:paramtypes", [DepC, DepB, DepA]) ], Cls); const container = new Container(); [DepA, DepB, DepC, Cls].forEach((i) => container.bind(i).toSelf().inSingletonScope()); container.get(Cls); expect(injectedA).toStrictEqual(new DepA()); expect(injectedB).toStrictEqual(new DepB()); expect(injectedC).toStrictEqual(new DepC()); }); }); //# sourceMappingURL=issue_928.test.js.map