mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
refactor(jsdoc-core): make Dependencies#reset accept a string
This commit is contained in:
parent
ad2cfd70ef
commit
004ce7392c
@ -1,3 +1,4 @@
|
||||
const _ = require('lodash');
|
||||
const Bottle = require('bottlejs');
|
||||
|
||||
/**
|
||||
@ -25,7 +26,7 @@ class Dependencies {
|
||||
registerClass(name, constructor, ...deps) {
|
||||
this._bottle.service(name, constructor, ...deps);
|
||||
// Remove the cached provider.
|
||||
this._bottle.middleware(name, (_, next) => {
|
||||
this._bottle.middleware(name, (provider, next) => {
|
||||
this._bottle.resetProviders([name]);
|
||||
next();
|
||||
});
|
||||
@ -40,7 +41,7 @@ class Dependencies {
|
||||
|
||||
this._bottle.serviceFactory(name, realFactory, ...deps);
|
||||
// Remove the cached provider.
|
||||
this._bottle.middleware(name, (_, next) => {
|
||||
this._bottle.middleware(name, (provider, next) => {
|
||||
this._bottle.resetProviders([name]);
|
||||
next();
|
||||
});
|
||||
@ -65,7 +66,9 @@ class Dependencies {
|
||||
}
|
||||
|
||||
reset(names) {
|
||||
if (!Array.isArray(names)) {
|
||||
if (_.isString(names)) {
|
||||
names = [names];
|
||||
} else if (!Array.isArray(names)) {
|
||||
throw new Error('Must provide an array of provider names');
|
||||
}
|
||||
|
||||
|
||||
@ -150,7 +150,25 @@ describe('@jsdoc/core/lib/dependencies', () => {
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('throws on non-array input', () => {
|
||||
it('accepts a string', () => {
|
||||
class Foo {}
|
||||
|
||||
container.registerClass('Foo', Foo);
|
||||
|
||||
expect(() => container.reset('Foo')).not.toThrow();
|
||||
});
|
||||
|
||||
it('accepts an array of strings', () => {
|
||||
class Foo {}
|
||||
class Bar {}
|
||||
|
||||
container.registerClass('Foo', Foo);
|
||||
container.registerClass('Bar', Bar);
|
||||
|
||||
expect(() => container.reset(['Foo', 'Bar'])).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws on non-array, non-string input', () => {
|
||||
expect(() => container.reset()).toThrowError();
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user