Comments (2)
I actually misunderstood this before and it's working as expected today. The TL;DR is kind of that you're using autoDetect
wrong in this case. You should be waiting for the fixture stableness rather than autoDetect
to cause stableness to be applied synchronously. Using your test component above, this works:
beforeEach(async () => {
await TestBed.configureTestingModule({
providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]
}).compileComponents();
});
it('should create the app', async () => {
@Component({template: '{{title()}}'})
class Example {
title = signal('');
constructor() {
effect(() => {
this.title.set('demo');
}, {allowSignalWrites: true});
}
}
const fixture = TestBed.createComponent(Example);
await fixture.whenStable();
expect(fixture.nativeElement.textContent).toEqual('demo'); // ✅
});
from angular.
Thanks @atscott, I totally agree with you. ComponentFixture#whenStable()
is indeed a way better option.
I think that my issue description was not very clear.
What I wanted to highlight is that there was a behavior change since the change of effect
scheduling in v17.1.0 (1f8c53c)
Since effects became scheduled as microtasks, tests that relied on synchronous change detection using ComponentFixture#detectChanges
were broken.
For example, Angular Testing Library currently relies on sync change detection instead of ComponentFixture#whenStable()
(cf. https://github.com/testing-library/angular-testing-library/blob/main/projects/testing-library/src/lib/testing-library.ts#L253)
It would be wise to switch to whenStable()
but then it raises another issue. There should be an opt-out when combined with fakeAsync
as calling whenStable()
with any pending timers in fakeAsync
will produce the following error: timer(s) still in the queue.
if we want to make assertions before flushing the timers.
from angular.
Related Issues (20)
- BrowserViewportScroller not honoring native scroll margin HOT 4
- Unit Testing guide has incorrect code HOT 1
- Angular compiler seemingly false negative warning : optional chaining refused on array item HOT 3
- ActivatedRoute in Directive: Snapshot.params are not getting updated HOT 2
- APP_INITIALIZER with HttpClient provoke memory leak in SSR projects HOT 8
- New Angular Docs website is not PWA compatible
- @for can't be used for forms where $index based calls on removeAt() are necessary HOT 1
- Recording already in progress issue in Profiler
- SSR won't render [style.background-image] with base64 URL values
- Btter Docs About Error handling in httpClient HOT 2
- No compile time error/warning in HTML template when Signals variable used without parenthesis HOT 2
- Fail to load docs HOT 1
- We couldn't start the tutorial app. HOT 2
- ngProjectedAs not working when used as static host property inside @Component
- "Could not resolve dependency" for ts version in webcontainers at adev HOT 1
- ESBuild not calling any http request in server side HOT 2
- Unable to hydrate nested anchor elements HOT 3
- Broken links on ng-template reference page HOT 1
- [tour-of-heroes/toh-pt1][Format with the UppercasePipe] adding pipe {{hero.name | uppercase }} requires "CommonModule" HOT 1
- fetch resulting in respons.json already parsed error HOT 2
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.