Skip to content

Commit

Permalink
add failing test for "this" in aspect (#77)
Browse files Browse the repository at this point in the history
* add failing test for "this" in aspect

* clean up after copy/paste
  • Loading branch information
matthewadams authored and mgechev committed Nov 18, 2018
1 parent ffa52fa commit 9401ccf
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/advices/this_in_aspect.spec.ts
@@ -0,0 +1,40 @@
import { Wove, resetRegistry, Metadata } from "../../lib/src/core";
import { aroundMethod } from "../../lib";

import { expect } from "chai";

describe("the \"this\" in an aspect", () => {
afterEach(() => {
resetRegistry();
});

it("should be bound correctly", () => {
const bar = "bar";

class AspectWithThis {
foo: string;

constructor() {
this.foo = bar;
}

@aroundMethod({ classNamePattern: /^Test$/, methodNamePattern: /^appendX$/ })
aroundMethod(meta: Metadata) {
if (meta.method.proceed) {
meta.method.proceed = false;
meta.method.result = this.foo;
}
}
}

@Wove()
class Test {
appendX(it: string) {
return `${it}x`;
}
}

const test = new Test();
expect(test.appendX("it")).to.equal(bar); // instead of "itx"
});
});

0 comments on commit 9401ccf

Please sign in to comment.