From fb967594aab186b383e35a57c23dfda6bcb64d00 Mon Sep 17 00:00:00 2001 From: Romke van der Meulen Date: Mon, 25 Feb 2019 14:02:56 +0100 Subject: [PATCH] doc(testing): add section on ignoring dependencies This describes a new feature of aurelia-testing introduced by https://github.com/aurelia/testing/pull/89 --- current/en-us/9. testing/1. components.md | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/current/en-us/9. testing/1. components.md b/current/en-us/9. testing/1. components.md index ef83774..e4b04ab 100644 --- a/current/en-us/9. testing/1. components.md +++ b/current/en-us/9. testing/1. components.md @@ -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 ``d by a template +from actually being loaded. + +```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("my-component"); + }); + + 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 -