From 5f3db1153e8af7907003e391466c014e4fa0ddd3 Mon Sep 17 00:00:00 2001 From: Evan Schultz Date: Fri, 17 Nov 2017 10:57:31 -0500 Subject: [PATCH] [#484] Investigate behavior when classes extend an abstract class --- src/decorators/dispatch.spec.ts | 58 ++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/decorators/dispatch.spec.ts b/src/decorators/dispatch.spec.ts index 39f074c..3027257 100644 --- a/src/decorators/dispatch.spec.ts +++ b/src/decorators/dispatch.spec.ts @@ -138,7 +138,7 @@ describe('@dispatch', () => { localReducer, }) class TestClass { - getBasePath = () => [ 'bar', 'foo' ] + getBasePath = () => ['bar', 'foo'] @dispatch() decoratedActionCreator(value: string): PayloadAction { return { @@ -165,4 +165,60 @@ describe('@dispatch', () => { }); }); }); + + describe('With class inheritence', () => { + abstract class Base { + public abstract getName(): string; + + @dispatch() + public doAction() { + return `${this.getName()} ${this.constructor.name}`; + + } + } + + class AAction extends Base { + public getName() { + return 'FOO'; + } + } + + class BAction extends Base { + public getName() { + return 'Bar'; + } + } + + class CAction extends BAction { + public getName() { + return 'Baz'; + } + } + + class DAction extends BAction { + public getName() { + return super.getName() + 'Baz'; + } + } + + fit('should call the call the method on the implemented class', () => { + const a = new AAction(); + const b = new BAction(); + const c = new CAction(); + const d = new DAction(); + a.doAction(); + expect(NgRedux.instance && NgRedux.instance.dispatch) + .toHaveBeenCalledWith('FOO AAction'); + b.doAction(); + expect(NgRedux.instance && NgRedux.instance.dispatch) + .toHaveBeenCalledWith('Bar BAction'); + c.doAction(); + expect(NgRedux.instance && NgRedux.instance.dispatch) + .toHaveBeenCalledWith('Baz CAction'); + d.doAction(); + expect(NgRedux.instance && NgRedux.instance.dispatch) + .toHaveBeenCalledWith('BarBaz DAction'); + }); + + }); });