I'm trying to write Angular test using jest :
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BookListComponent],
}).compileComponents();
}));
When i launched :
npm run test:watch
I got this error :
error TS2304: C annot find name 'async'.
You have to change async to waitForAsync in Angular 11 because they changed it. They changed it because the async you import from @angular/core/testing in previous versions is similar to the native async of JavaScript and could cause confusion.
import { waitForAsync } from '@angular/core/testing';
.....
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [BookListComponent],
}).compileComponents();
}));
Link for waitForAsync.
async is a not a function. Try it like this:
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [BookListComponent],
}).compileComponents();
});
I'm not to sure if you would even need to mark the function as async because you don't use the await inside your before each.
Have a look at the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With