@blotch/angular-lynx-testing-library
Renders a component through the Lynx renderer in a unit test, then finds and taps its elements with Testing Library queries. import { render } from '@blotch/angular-lynx-testing-library';
Usage
Add the library with ng generate @blotch/angular-lynx:add-testing, and run tests with ng test. The unit-test builder loads the library's setup, so there's no setup file to write.
API
render(component, options?)
Bootstraps component as a Lynx app, renders it into the test's DOM, and resolves once the first render is done.
- It first destroys the app a previous
render()left, and clearsdocument.body. - The app gets
provideZonelessChangeDetection(),provideRenderer()and youroptions.providers. - Elements render under a
<page>element, the result'scontainer.
cleanup()
Destroys the rendered app. It runs after every test, so you rarely call it. To turn that off, set the environment variable ATL_SKIP_AUTO_CLEANUP=true.
waitForUpdate()
Waits one task (a setTimeout of 0), so the change detection Angular scheduled can run, then runs change detection once more. Await it after fireEvent or after setting a signal, before you check the rendered output.
fireEvent(element, event)
Fires a Lynx event at element, which runs the matching template handler, such as (bindtap). The methods and their bindings are in the Event reference.
init: properties to set on the event.{ detail: { value: 'hi' } }arrives as$event.detail.value.init.eventType: the binding to reach.'bindEvent'(the default) reaches(bind*)handlers. Use'catchEvent'for(catch*)handlers.
fireEvent doesn't render. The handler runs before fireEvent returns, so a spy or a signal you read directly already shows the change. Angular renders the result in a change detection it schedules for after the current task. Await waitForUpdate() before checking the rendered output.
eventMap
The events that fireEvent has a method for, keyed by event name.
Types
RenderOptions
RenderResult
componentRef.setInput() works under ng test, which compiles components ahead of time. Under plain Vitest, which compiles them at runtime, it can't see signal inputs. Set a writable signal on componentRef.instance instead.
Re-exports
The package also has a @blotch/angular-lynx-testing-library/setup entry, which prepares the Lynx test environment. ng test loads it for you.
