Comment tester la boucle forEach dans le jasmin en utilisant le karma ?? Le code composant est le suivant: -TypeError: studentsList.forEach n'est pas une fonction. Jasmine Unit Testing (Angular 2)
getData(studentsList:any, day:any, game:any){
let strength:any;
let location:string;
if(studentsList){
studentsList.forEach(value => {
strength=value.schedule[day][game].strength;
location=value.schedule[day][game].location;
});
}
}
les données présentes dans studentsList est: -
(Edit: - l'on dirait que les données sont mis à jour ce)
[{
"activityName": "tournament1",
"schedule": {
"first": {
"Baseball": {
"strength": 23,
"location": "abc"
}
},
"second": {
"Cricket": {
"strength": 20,
"location": "bcd"
}
},
"third": {
"Football": {
"strength": 19,
"location": "cde"
}
}
}
},
{
"activityName": "tournament2",
"schedule": {
"first": {
"Baseball": {
"strength": 23,
"location": "abc"
}
},
"second": {
"Cricket": {
"strength": 20,
"location": "bcd"
}
},
"third": {
"Football": {
"strength": 19,
"location": "cde"
}
}
}
},{
"activityName": "tournament3",
"schedule": {
"first": {
"Baseball": {
"strength": 23,
"location": "abc"
}
},
"second": {
"Cricket": {
"strength": 20,
"location": "bcd"
}
},
"third": {
"Football": {
"strength": 19,
"location": "cde"
}
}
}
}]
C'est le test que j'ai essayé: -
it('should check getData()',() => {
fixture = TestBed.createComponent(GameComponent);
const app = fixture.debugElement.componentInstance;
const data={
"activityName": "tournament",
"schedule": {
"first": {
"Baseball": {
"strength": 23,
"location": "abc"
}
},
"second": {
"Cricket": {
"strength": 20,
"location": "bcd"
}
},
"third": {
"Football": {
"strength": 19,
"location": "cde"
}
}
}
}
app.getData(data, 'first', 'Baseball');
fixture.detectChanges();
expect(app.location).toContain('abc');
expect(app.location).toContain('bcd');
expect(app.location).toContain('cde');
}
Mais je continue à le faire carChaque fonction n'est pas une fonction. Au lieu de donner des données statiques dans le test dois-je aller d'une autre manière?
'forEach' nécessite un tableau –