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

Testing > DI dependencies #445

Open
baerrach opened this issue Jul 15, 2019 · 1 comment
Open

Testing > DI dependencies #445

baerrach opened this issue Jul 15, 2019 · 1 comment

Comments

@baerrach
Copy link
Contributor

https://aurelia.io/docs/testing/components#using-a-real-parent-view-model

In "A Custom Attribute Test with Real Parent View-model and DI dependencies"

The example is

  import {StageComponent} from 'aurelia-testing';
  import {bootstrap} from 'aurelia-bootstrapper';
  import {MyComponent} from 'src/my-component';
  import {Container} from 'aurelia-dependency-injection';
  import {MyService} from 'src/my-service';
  
  describe('MyAttribute', () => {
    let component;
    let container;
    let viewModel;
    let myService;
  
    beforeEach(() => {
      container = new Container();
      myService = container.get(MyService);
      viewModel = container.get(MyComponent);
      component = StageComponent
          .withResources('src/my-attribute')
          .inView('<div my-attribute.bind="color">Bob</div>')
          .boundTo(viewModel);
    });
    //...
  });

Shouldn't the .get calls be .registerInstance instead?
How does StageComponent know about the newly created Container?

@EisenbergEffect
Copy link
Contributor

EisenbergEffect commented Jul 15, 2019

The container will auto-register services if you call get and there’s not a prior registration. However, the fact that the testing helper is able to access them from a container instance that doesn’t appear to be related is odd. I know how this is working (it’s kind of a bad design we have in the framework that we’ve eliminated for vNext) but that doesn’t make it particularly easy to understand.

@bigopon @zewa666 What do you guys think? Can we make some improvement here? Intuitively, one would expect the StageComponent API to receive an instance of the custom container. I can’t recall if we have a way to do that or not though. If we do, it would probably be clearer if we updated this example to use that.

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