Angular unit testing with Jasmine: how to remove or modify spyOn
You can just overwrite it updateService.getUpdate = jasmine.createSpy().and.returnValue(etc)
You can just overwrite it updateService.getUpdate = jasmine.createSpy().and.returnValue(etc)
async will not allow the next test to start until the async finishes all its tasks. What async does is wrap the callback in a Zone, where all asynchronous tasks (e.g. setTimeout) are tracked. Once all the asynchronous tasks are complete, then the async completes. If you have ever worked with Jasmine outside out Angular, … Read more
It does seem like this is a very general error, however in my case the problem was either that I didn’t run karma start from the correct folder, or that I didn’t restart it after changing the configuration. I’ll leave this question open and hopefully it can become a resource for others who experience this … Read more
I had the same error after creating a new project the yeoman angular generator (yo angular). The solution for me was adding “karma-jasmine” to the devDependencies in packages.json and running “npm install” again. npm install karma-jasmine –save-dev This solved the error message “No provider for “framework:jasmine”!” I also had to add a karma browser launcher … Read more
First you need to start karma server with karma start Then, you can use grep to filter a specific test or describe block: karma run — –grep=testDescriptionFilter
Future readers: you can also get this exact error, when you forget to place animations: [ <yourAnimationMethod()> ] on your @Component ts file. that is if you’re using [@yourAnimationMethod] on the HTML template, i.e. angular animations.
FYI: you can find the exact error thrown just by open DevTools Console once your tests are running. As a quickfix you can try to run your tests without sourcemaps: CLI v6.0.8 and above –source-map=false CLI v6.0.x early versions –sourceMap=false CLI v1.x –sourcemaps=false Shortcut ng test -sm=false might also work There is an open issue … Read more
You passed HeroDetailComponent to TestBed.createComponent() without declaring the component first: TestBed.configureTestingModule({ imports: [AppModule, CommonModule, FormsModule, SharedModule, HeroRoutingModule, ReactiveFormsModule ], providers: [ {provide: APP_BASE_HREF, useValue: “https://stackoverflow.com/”} ], declarations: [HeroDetailComponent] }).compileComponents(); Hope it helps. Update for following errors in your test: Added some more imports (just take your HeroModule as a blueprint because that’s basically what you … Read more
Edit Jasmine 2.8 adds arrayWithExactContents that will succeed if the actual value is an Array that contains all of the elements in the sample in any order. See keksmasta’s answer Original (outdated) answer If it’s just integers or other primitive values, you can sort() them before comparing. expect(array1.sort()).toEqual(array2.sort()); If its objects, combine it with the … Read more