Skip to content

Commit

Permalink
Create autobind-decorator-tests.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
NoHomey authored Sep 8, 2016
1 parent 2aa23e2 commit 1e2fe02
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions autobind-decorator/autobind-decorator-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// <reference path="autobind-decorator.d.ts" />

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'

0 comments on commit 1e2fe02

Please sign in to comment.