From 1e2fe02942c1f7ee1732fb5e725d3e2194e75e50 Mon Sep 17 00:00:00 2001 From: Ivo Stratev Date: Thu, 8 Sep 2016 19:18:35 +0300 Subject: [PATCH] Create autobind-decorator-tests.ts --- .../autobind-decorator-tests.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 autobind-decorator/autobind-decorator-tests.ts diff --git a/autobind-decorator/autobind-decorator-tests.ts b/autobind-decorator/autobind-decorator-tests.ts new file mode 100644 index 0000000000..7ee65a60b9 --- /dev/null +++ b/autobind-decorator/autobind-decorator-tests.ts @@ -0,0 +1,43 @@ +/// + +import autobind = require('autobind-decorator'); + +class Test { + public static what: string = 'static'; + + @bind + public static test(): void { + console.log(this.what); + } + + public constructor(public what: string) { + this.what = what; + } + + @bind + public test(): void { + console.warn(this.what); + } +} + +const tester: Test = new Test('bind'); +const { test } = tester; +tester.test(); // warns 'bind'. +test(); // warns 'bind'. +Test.test(); // logs 'static'. + +@autobind +class Component { + public constructor(private someMember: string) { + this.someMember = someMember; + } + + public somMethod(): void { + console.error(this.someMember); + } +} + +const component: Component = new Component('React vs Angular2'); +const { somMethod } = component; +component.someMethod(); // errors 'React vs Angular2' +somMethod(); // errors 'React vs Angular2'