mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
feature(jsdoc-core): allow dependencies to be reset
This commit is contained in:
parent
29b64a4638
commit
ad2cfd70ef
@ -63,6 +63,14 @@ class Dependencies {
|
||||
registerValue(name, value) {
|
||||
this._bottle.value(name, value);
|
||||
}
|
||||
|
||||
reset(names) {
|
||||
if (!Array.isArray(names)) {
|
||||
throw new Error('Must provide an array of provider names');
|
||||
}
|
||||
|
||||
this._bottle.resetProviders(names);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dependencies;
|
||||
|
||||
@ -148,4 +148,24 @@ describe('@jsdoc/core/lib/dependencies', () => {
|
||||
expect(() => container.registerValue('name', new Set())).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('throws on non-array input', () => {
|
||||
expect(() => container.reset()).toThrowError();
|
||||
});
|
||||
|
||||
it('removes cached singletons', () => {
|
||||
class Foo {}
|
||||
|
||||
let instance1;
|
||||
let instance2;
|
||||
|
||||
container.registerSingleton('Foo', Foo);
|
||||
instance1 = container.get('Foo');
|
||||
container.reset(['Foo']);
|
||||
instance2 = container.get('Foo');
|
||||
|
||||
expect(instance2).not.toBe(instance1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user