Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions current/en-us/9. testing/1. components.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,56 +308,6 @@ 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. Note that you need to provide the resolved module path,
which may not be exactly the same as the path you used in `<require>`.

```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("src/my-component"); // this should be the resolved path
});

it("doesn't load the subcomponent", done => {
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