forked from aurelia/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc(testing): add section on ignoring dependencies
This describes a new feature of aurelia-testing introduced by aurelia/testing#89
- Loading branch information
1 parent
21791b8
commit fb96759
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
RomkeVdMeulen
Author
Owner
|
||
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 - | ||
|
might want to switch this to async/await