Comments (4)
Your test doesn't call fixture.detectChanges()
before starting to interact with the component. So its lifecycle is never started (ngOnInit
isn't called).
from angular.
Per above.
from angular.
Your test doesn't call
fixture.detectChanges()
before starting to interact with the component. So its lifecycle is never started (ngOnInit
isn't called).
ok.. it does work when I move the change detection above dispatchEvent
. But why? Below is an example from angular.io
it('should convert hero name to Title Case', () => {
// get the name's input and display elements from the DOM
const hostElement: HTMLElement = harness.routeNativeElement!;
const nameInput: HTMLInputElement = hostElement.querySelector('input')!;
const nameDisplay: HTMLElement = hostElement.querySelector('span')!;
// simulate user entering a new name into the input box
nameInput.value = 'quick BROWN fOx';
// Dispatch a DOM event so that Angular learns of input value change.
nameInput.dispatchEvent(new Event('input'));
// Tell Angular to update the display binding through the title pipe
harness.detectChanges();
expect(nameDisplay.textContent).toBe('Quick Brown Fox');
});
from angular.
detectChanges
is responsible for invoking the lifecycle hooks (ngOnInit
) in your case.
If you fire the event before the subscription starts, you won't have any changes reported.
I agree the doc isn't great, as it doesn't show that the test file actually invokes detectChanges
when creating the component.
from angular.
Related Issues (20)
- Missing RouterCreateURL HOT 1
- contentChildren signal value changes before child components are initialised HOT 4
- Make built-in validator directives standalone
- Incomplete docs for NgComponentOutlet directive
- Invalid route for esbuild documentation link
- Animation transform scale not working correctly
- :leave animation in route child breaks route transition
- HTTP client - Test requests heads to wrong angular.dev link HOT 1
- Link does not work. HOT 1
- How to capture errors outside Angular context in zoneless? HOT 2
- RouterLinkActive doesn't work on an ancestor element as claimed by the docs HOT 1
- Reference page for `inject` only lists the overload for injecting a `HostAttributeToken` HOT 1
- Missing docs about effect and change detection phase HOT 2
- Link to Location not shown properly in API Reference page HOT 2
- ControlValueAccessor's setDisabledState should be called before the validate function is called HOT 3
- Control flow migration: *ngIf under switch doesn't migrate to new syntax HOT 5
- Unable to use `HostAttributeToken` on application root component HOT 2
- Exception when using null coalescing operator in @for track expression HOT 2
- baseUrl link broken HOT 1
- docs: link with extra whitespace in NgComponentOutlet HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.