Skip to content

Commit

Permalink
doc(testing): add section on ignoring dependencies
Browse files Browse the repository at this point in the history
This describes a new feature of aurelia-testing introduced by
aurelia/testing#89
  • Loading branch information
RomkeVdMeulen committed Feb 25, 2019
1 parent 21791b8 commit fb96759
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions current/en-us/9. testing/1. components.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,55 @@ describe('MyAttribute', () => {
Now the service dependency for `MyComponent` will be resolved through DI automatically.
## Ignoring dependencies
You might want to test a component that is composed of subcomponents with possible side-effects that you don't want to encounter during your test. In that case, you can prevent specific resources from being loaded during the test by calling `ignoreDependencies()`. This will prevent a module `<require>`d by a template
from actually being loaded.
```HTML A composed component - template
<template>
<require from="my-component"></require>

<my-component first-name="Alice"></my-component>

${message}
</template>
```
```JavaScript A composed component - View Model
class MyParent {
message = "Hello from the parent!"
}
```
```JavaScript Ignoring specific resources when loading a component for testing
import {StageComponent} from 'aurelia-testing';
import {bootstrap} from 'aurelia-bootstrapper';

describe('MyParentComponent', () => {
let component;

beforeEach(() => {
component = StageComponent
.withResources('src/my-parent-component')
.inView('<my-composed-component></my-parent-component>')
.ignoreDependencies("my-component");
});

it("doesn't load the subcomponent", done => {

This comment has been minimized.

Copy link
@zewa666

zewa666 Feb 25, 2019

might want to switch this to async/await

This comment has been minimized.

Copy link
@RomkeVdMeulen

RomkeVdMeulen Feb 25, 2019

Author Owner

I considered that, but since the rest of the article is still using .then() that might be confusing. I suggest rewriting the entire article to switch the code samples to async / await. But that could be done in a separate PR.

component.create(bootstrap).then(() => {
expect(component.element.textContent.trim()).toEqual("Hello from the parent!");

done();
});
});

afterEach(() => {
component.dispose();
});
});
```
## Improving Readability with Multi-line Strings
You can improve the readability of your complex views by using template literals in your tests -
Expand Down

0 comments on commit fb96759

Please sign in to comment.