40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
const { expect } = require('chai');
|
|
const Container = require('../src/core/Container');
|
|
|
|
describe('DI Container', () => {
|
|
let container;
|
|
|
|
beforeEach(() => {
|
|
container = new Container();
|
|
});
|
|
|
|
it('should register and resolve a singleton service', () => {
|
|
// TODO 1: Teszt: singleton service mindig ugyanazt az instance-t adja vissza
|
|
// 1. Regisztrálj egy service-t: container.register('TestService', () => ({ id: Math.random() }), 'singleton');
|
|
// 2. Resolve-old kétszer: const instance1 = container.resolve('TestService');
|
|
// 3. Ellenőrizd, hogy ugyanaz az instance: expect(instance1).to.equal(instance2);
|
|
});
|
|
|
|
it('should create new instance for transient service', () => {
|
|
// TODO 2: Teszt: transient service mindig új instance-t ad vissza
|
|
// 1. Regisztrálj egy transient service-t: container.register('TransientService', () => ({ id: Math.random() }), 'transient');
|
|
// 2. Resolve-old kétszer
|
|
// 3. Ellenőrizd, hogy különböző instance-ok: expect(instance1).to.not.equal(instance2);
|
|
});
|
|
|
|
it('should resolve scoped service within scope', () => {
|
|
// TODO 3: Teszt: scoped service scope-on belül ugyanaz, kívül más instance
|
|
// 1. Regisztrálj egy scoped service-t: container.register('ScopedService', () => ({ id: Math.random() }), 'scoped');
|
|
// 2. Hozz létre egy scope-ot: const scope1 = container.createScope();
|
|
// 3. Resolve-old kétszer ugyanabban a scope-ban
|
|
// 4. Ellenőrizd, hogy ugyanaz az instance
|
|
// 5. Hozz létre új scope-ot és resolve-old ott is
|
|
// 6. Ellenőrizd, hogy különböző instance-ok a két scope között
|
|
});
|
|
|
|
it('should throw error for unregistered service', () => {
|
|
// TODO 4: Teszt: nem regisztrált service resolve hiba dobása
|
|
// Tipp: expect(() => container.resolve('NonExistentService')).to.throw();
|
|
});
|
|
});
|