Questions tagged [angular2-testing]
289 questions
1
vote
1 answer
angular unit test ngOninit
The testbed config is
TestBed.configureTestingModule({
declarations: [ EditPersorgaComponent, ArrayFromIntPipe, TeamFilterPipe ],
schemas: [ NO_ERRORS_SCHEMA ],
imports: [ HttpClientModule, NgbModule.forRoot(),…

Ramakanth Reddy
- 129
- 1
- 12
1
vote
3 answers
Is it possible to list array of component dependency injectors?
How do I list all the dependency injectors of a component in angular?
This requirement is for unit testing.
I have an instance of a component created as follows :
component = fixture.componentInstance();
So in my test case, I need something like…

Amit Chigadani
- 28,482
- 13
- 80
- 98
1
vote
1 answer
Not able to reset providers in beforeEach after creating TestBed once in beforeAll
We writing test case for a component which has many nested services and components (we cannot mock every service for our requirement). We have created module which contains all the components and services. In spec.ts file we have added module in…

Sudheer KB
- 1,596
- 14
- 28
1
vote
0 answers
test function whenstable of angular2 didn't wait for promise resloves
I'm using SystemJsModuleLoader to load modules, it works just fine.
But when I test my app, whenStable didn't works as it describes.
It resolves so fast that systemjsLoader.load() hasn't resolved yet.
So I can't do test in whenStable().then(my test…

Elliot Xu
- 11
- 1
1
vote
2 answers
Angular2 + Jasmine Event Object
I have this simple method which needs to be tested:
public onLayerContainerClick(event: Event): void {
event.stopPropagation();
event.preventDefault();
if (event.srcElement.classList.contains('dpm-info__layerContainer')) {
…

pop
- 3,464
- 3
- 26
- 43
1
vote
1 answer
Angular 2 Testing: Spying on ngOnInit() in beforeEach?
Context
My issue is that my ngOnInit function calls many sub functions asynchronously by using Firestore to populate a form from one document as well as subscribing to various collections to display lists of data. This gets very tedious to test as I…

Matthew Mullin
- 7,116
- 4
- 21
- 35
1
vote
0 answers
Angular 2 karma unit tests, template error
I've got a problem - when I try to configure testbed, it throws error
Failed: Uncaught (in promise): Failed to load /student-register.component.html
I tried to solve this problem by overriding the component and setting empty template, but I'll need…

Jędrek Markowski
- 444
- 3
- 6
- 25
1
vote
1 answer
Angular2 Unit Test Mouse Events
I want to test one of methods which helps in closing Modal Window when closed outside of Modal Window container.
Component Method
public hide(): void {
this.visibleAnimate = false;
setTimeout(() => { this.visible = false; }, 200);
…

Gags
- 3,759
- 8
- 49
- 96
1
vote
1 answer
Angular 2 testing, template update not being detected
I am testing a component which dinamically inserts a checkbox in its template when ngAfterViewInit lifecycle hook is called.
export class MyComponent {
ngAfterViewInit() {
// checkbox insertion in the template here
...
}
...
}
This…

Zucca
- 561
- 1
- 7
- 21
1
vote
1 answer
How to write a unit test spec for a provider using http request in ionic2?
I want to test my provider class, so I am unable to write spec for providers.
My provider is as follows:
service.ts
//imports are done correctly.
@Injectable()
export class Service {
constructor(private http: Http) { }
…

user8348978
- 81
- 1
- 1
- 7
1
vote
0 answers
Angular2 karma test set @Input variable
I am running an angular2 unit test. the component has an Input binding.
I tried to set in manually like following:
fixture = TestBed.createComponent(Step2Component);
component = fixture.componentInstance;
component.notificationModel = new…

Cosmin D
- 639
- 1
- 11
- 24
1
vote
0 answers
Writing test cases for form elements in angular using jasmine
I am trying to test the input boxes in angular 4 using the angular testing framework. However, I can't get the value of the input box inside a form.
Referring to the angular testing docs, I could see that I need to fire some sort of Input event,…

basum
- 319
- 1
- 3
- 18
1
vote
1 answer
Testing ngOnChanges with SimpleChanges in Angular 2
I have the code below and I need to know how I could use spyon with previousValue and currentValue in my test to coverage the conditional if (cur !== prev && cur === 100).
ngOnChanges(changes: SimpleChanges) {
if (changes['highlightData'] &&…

Marcio M.
- 371
- 1
- 6
- 15
1
vote
1 answer
Angular 2 Jasmine Test fails
New to both Angular 2 and core testing.
I have a MovieComponent that uses a injected MovieService. Trying to learn, so used route params. Code is working as expected.
describe('MovieComponent', () => {
let component: MovieComponent;
let fixture:…

user2693135
- 1,206
- 5
- 21
- 44
1
vote
0 answers
Angular 2 Testing Service with nested Service
base.service.ts
export class BaseService {
constructor(private http:Http){}
search(segment: string, param: string){
//build url
this.http.get(....){}
}
}
my.service.ts
export class MyService {
…

Sumo NL
- 11
- 1