diff --git a/src/WidgetBase.ts b/src/WidgetBase.ts index 47785611..19057eb4 100644 --- a/src/WidgetBase.ts +++ b/src/WidgetBase.ts @@ -421,7 +421,7 @@ export class WidgetBase

extends E specificDecoratorList.push(...value); } else { - const decorators = this._decoratorCache.get(decoratorKey) || []; + const decorators = this.getDecorator(decoratorKey); this._decoratorCache.set(decoratorKey, [ ...decorators, ...value ]); } } diff --git a/tests/unit/WidgetBase.ts b/tests/unit/WidgetBase.ts index e6e3bc95..7211e629 100644 --- a/tests/unit/WidgetBase.ts +++ b/tests/unit/WidgetBase.ts @@ -1379,5 +1379,24 @@ registerSuite({ assert.equal(testWidget.getAfterRenders().length, 1); assert.equal(testWidget2.getAfterRenders().length, 2); + }, + 'decorator cache is populated when addDecorator is called after instantiation'() { + class TestWidget extends WidgetBase { + constructor() { + super(); + + this.addDecorator('beforeRender', function() {}); + this.addDecorator('afterRender', function() {}); + } + + getDecoratorCount(key: string): number { + return this.getDecorator(key).length; + } + } + + const testWidget = new TestWidget(); + + assert.equal(testWidget.getDecoratorCount('beforeRender'), 2, 'beforeRender = 1 (existing) + 1'); + assert.equal(testWidget.getDecoratorCount('afterRender'), 1, 'afterRender = 0 (existing) + 1'); } });