Lightweight utility functions to test Angular components.
Table of Contents
ngx-testing-library from npm and add it your
npm install ngx-testing-library --save-dev
- test your UI components the way your users are using it
- making your tests resilient to implementation changes
ngx-testing-library is an Angular adapter around dom-testing-library, which provides lightweight utility functions to test UI components. Your tests will work with actual DOM nodes.
This library only consists of one function,
createComponent which is used to setup the Angular
TestBed and creates the component fixture.
This method can be used in two ways:
Based on a template:
;createComponent'<my-component [prop]="1"></my-component>', options;
Based on a component type:
The second parameter in
createComponent is the
options parameter, which looks like this:
detectChanges on the fixture
declarations: passed to the
providers: passed to the
imports: passed to the
schemas: passed to the
createComponent function returns an object consisting all of the query functions from dom-testing-library, all the event functions exposed from
fireEvent, and adds the following properties:
Every event runs
detectChangeson the fixture.
The DOM node containing the Angular component.
All of the dom-testing-library query functions are binded to this container.
debug() => void
Prints out the container.
The Angular fixture.
getFromTestBed(token: any, notFoundValue?: any) => any
Calls the the Angular
You can find some examples in the tests folder.
Here is how the "default" specifications can be written with
;;it`should have as title 'my-awesome-app'`,;it`should render title in a h1 tag`,;