Questions tagged [angular2-testing]
289 questions
5
votes
0 answers
Angular 2 Unit testing component with other component dependencies
Basically I have a component that look like this:
export class CmpB extends CmpA {
variableA:any = {};
@Input() config:any = {};
constructor(private serviceA: serviceA,
@Optional() private CmpC?: CmpC) {
super();
}
…

elasticrash
- 1,181
- 1
- 12
- 30
5
votes
1 answer
How to test transclusion (ng-content) in Angular2?
i have a component to test as follow :
import {Component, OnInit, Input} from "@angular/core";
@Component({
selector: 'column',
template: ' ',
host: {
'[class]': '"col col-" + width'
}
})
export…

semirturgay
- 4,151
- 3
- 30
- 50
5
votes
1 answer
Angular: Testing HTTP with MockBackend, is async() really required?
I'm using MockBackend to test code that depends in @angular/http.
All the examples around the web use an asynchronous test setup, like here:
thoughtram: Testing Services with Http in Angular
describe('getVideos()', () => {
it('should return an…

Johannes Hoppe
- 251
- 3
- 10
5
votes
1 answer
What is TestBed in Jasmine
I am new to Jasmine with Angular 2, I am frequently working with the TestBed object when writting a Testcase and getting the error:Please call "TestBed.compileComponents" before your test.
How do I solve this error?
@Component({
…

fruitjs
- 745
- 2
- 10
- 25
5
votes
2 answers
Angular 2 CLI Jasmine unit test fails when using beforeAll instead of beforeEach
I created a new project with NG-CLI (beta.15) and modified the app.component.spec to change the beforeEach to to a beforeAll and it caused the tests to fail with the following error:
Failed: Cannot create the component AppComponent as it was not…

HisDivineShadow
- 1,036
- 1
- 12
- 21
5
votes
2 answers
Running Angular2 tests that call setTimeout errors with "Cannot use setInterval from within an async zone test"
I'm upgrading our Angular2 app to use rc4 and I started getting an error on my unit tests:
Cannot use setInterval from within an async zone test
My widget makes a request for data from its ngOnInit method and puts up a loading indicator while that…

Ruan Mendes
- 90,375
- 31
- 153
- 217
5
votes
1 answer
How do you inject an angular2 service into a unit test? (RC3)
I am using RC3. I am implementing the new Angular2 router as documented here: https://angular.io/docs/ts/latest/guide/router.html
Everything works fine but I am having problem in unit testing. Specifically, I cannot inject Angular2 services into my…

danday74
- 52,471
- 49
- 232
- 283
4
votes
1 answer
Need to resolve the service dependency error with the component using karma jasmine
My aim is to unit test NewServicesRequestsComponent , I was able to resolve other dependencies but stuck with the service dependency named GenericService
I tried out resolving XHRbackend error by giving it as a provider in my spec file and using…

Enthu
- 512
- 2
- 13
- 38
4
votes
2 answers
Not able to change a component's property from unit test
I am trying to write a test to ensure that my method returns the right value based on one of the component's properties.
So in my unit test I want to set the value of the component's properties and then call the component's method that is supposed…

Chris Lang
- 384
- 2
- 19
4
votes
0 answers
how to test Observable.combineLatest
Observable.combineLatest(userService.getCurrentUser(),someDataService.getAllData(),
(currentUser, someData) => {
this.currentUser = currentUser;
this.someData = someData;
}).subscribe()
I am using this code in my ngOninit…

Gal Yaish
- 71
- 3
4
votes
3 answers
Angular 2 Karma tests have started to fail can't capture browser
This seems like a project setup problem in someway. This was working previously. I don't have the knowledge that these error messages help me to start. Does anyone have some advice on where to start diagnosing the problem?
21 05 2017…

Pompey Magnus
- 2,191
- 5
- 27
- 40
4
votes
2 answers
Angular testing example components fail to load templates in karma
I'm running the Banner-Spec.testing take it from here.
While running npm test got this error:
Chrome 57.0.2987 (Mac OS X 10.11.6): Executed 0 of 3 SUCCESS (0 secs / 0 secs)
Chrome 57.0.2987 (Mac OS X 10.11.6) BannerComponent (templateUrl) no title…

Gabriel Muñumel
- 1,876
- 6
- 34
- 57
4
votes
0 answers
Angular 2 unit test doesn't wait for promise to return
I have the following component method:
onSignup() {
if (this.form.valid) {
let email = this.form.value.email;
let password = this.form.value.password;
this.usersService.signup(email, password)
.then(() => {
…

mario595
- 3,671
- 7
- 34
- 57
4
votes
2 answers
Unable to test a component with a service
After reading this guide I've decided to test my simple login page which contains just 2 input boxes and a submit button. The component then uses a LoginService to pass these data to backend.
( Also note that I'm new to Unit testing as such, so I'm…

Alexus
- 1,887
- 1
- 23
- 50
4
votes
1 answer
Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule' - karma-jasmine
I'm getting error during creating Test component instance.
let comp: TaskviewComponent;
let fixture: ComponentFixture;
let deTaskTitle: DebugElement;
let elSub: HTMLElement;
describe('TaskviewComponent', () => {
beforeEach( () => {
…

Protagonist
- 1,649
- 7
- 34
- 56