@triviality/core
Version:
Purely typed service container
26 lines • 1.06 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var ramda_1 = require("ramda");
var ConstructContext_1 = require("../ConstructContext");
var MyService = /** @class */ (function () {
function MyService(_a, _b) {
// noop.
}
return MyService;
}());
it('Can inject services', function () {
var fetchService = jest.fn().mockReturnValueOnce(ramda_1.always(1)).mockReturnValueOnce(ramda_1.always('test'));
expect(ConstructContext_1.constructServiceByTags(fetchService)(MyService, 'a', 'b')()).toEqual(new MyService(1, 'test'));
});
it('Should request dependencies when needed ', function () {
var fetchService = jest.fn();
var service = ConstructContext_1.constructServiceByTags(fetchService)(/** @class */ (function () {
function class_1() {
throw new Error('Should not be called');
}
return class_1;
}()), 'a', 'b');
expect(service).toBeInstanceOf(Function);
expect(fetchService).not.toBeCalled();
});
//# sourceMappingURL=ConstructContext.test.js.map
;