diff --git a/current/en-us/9. testing/1. components.md b/current/en-us/9. testing/1. components.md index ef83774..15ee1f5 100644 --- a/current/en-us/9. testing/1. components.md +++ b/current/en-us/9. testing/1. components.md @@ -308,6 +308,56 @@ 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 ``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 ``. + +```HTML A composed component - 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('') + .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 -