Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use externalized aspect #65

Closed
matthewadams opened this issue Oct 10, 2018 · 3 comments
Closed

Can't use externalized aspect #65

matthewadams opened this issue Oct 10, 2018 · 3 comments

Comments

@matthewadams
Copy link
Collaborator

Trying to use an aspect defined in an external file & failing.

Failing test can be found at https://github.com/SciSpike/aspect.js/blob/external-aspects/test/advices/sync_advices.spec.ts#L305
(that's in forked repo https://github.com/SciSpike/aspect.js, branch external-aspects).

Code is effectively

// in file external_aspect.ts
import { aroundMethod, Metadata } from "../../lib";
import { expect } from "chai";

export default class ExternalAspect {
  @aroundMethod({ classNamePattern: /.*/, methodNamePattern: /.*/ })
  around(metadata: Metadata) {
    expect(this).to.deep.equal(ExternalAspect.prototype);
    expect(metadata.className).to.equal('Demo');
    expect(metadata.method.name).to.equal('get');
    expect(metadata.method.args).to.deep.equal([42, 1.618]);
    expect(metadata.method.invoke).to.be.a('function');

    metadata.method.proceed = false
    metadata.method.result = 'ExternalAspect'
  }
}

Failing test code is

import ExternalAspect from './external_aspect'

// ...

  describe('AroundAdvice', () => {
  // ...
    it('should invoke the external advice with the appropriate metadata', () => {
      let demo: any;

      @Wove()
      class Demo {
        get(foo: any, bar: any): string { return 'Demo' }
      }

      demo = new Demo();
      expect(demo.get(42, 1.618)).to.equal('ExternalAspect');
    });
  });

// ...

Created similar test using inline aspect that's passing at https://github.com/SciSpike/aspect.js/blob/external-aspects/test/advices/sync_advices.spec.ts#L279.

@mgechev
Copy link
Owner

mgechev commented Oct 10, 2018

Everything works properly in the example I just pushed.

@matthewadams
Copy link
Collaborator Author

Ok. It looks like the key difference is that instead of using

import ExternalAspect from './external_aspect'

The form of the import statement needs to be

import './external_aspect'

Case closed! :)

@matthewadams
Copy link
Collaborator Author

#66 proves this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants