Cool, I have a directive (that has been already written) and now I'm trying to create the unit tests for this directive. The directive has a link function, and in this link function there is a load() function, which gets some data from a service and stores it in an array. Then this array is stored on the scope.
`link: function(scope){
var TASK_TABLE_NAME = 'Task__ap';
function loadTasks(){
SobjectService.getByFilters(TASK_TABLE_NAME, {}, scope.limit, { ActivityDate : 'DESC' }).then(function(res){
scope.tasks = [];
_.each(res, function(task){
scope.tasks.push(task);
scope.$apply();
});
});
}` Similar to this:
So I'd like to test that the scope.tasks is empty and then populated, but I can't access the tasks array in my test.
vm.test = new Date(), all works fine.
Hi,
https://stackblitz.com/edit/angular-okulty?file=app/fontcolor.directive.ts
isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
<span class="break">
<label class="switch">
<input type="checkbox" checked>
<span class="slider round"></span>
</label>
</span><input type="number" name="Density" [(ngModel)]="op.Ro" placeholder="0" required #density="ngModel" [style.width.px]="80">
<ons-input id="username" modifier="underbar" placeholder="Nombre de usuario" float ng-model="page.username" ></ons-input>
if (($scope.page.username.length==0)){
ons.notification.alert({
title: 'Error al iniciar sesión',
message: 'Intruduce el usuario y contraseña.',
buttonLabels: 'Aceptar',
callback: function (answer) {
}
});
}
Cannot read property 'username' of undefined
hi,
https://stackblitz.com/edit/angular-mj8xcu?file=app/example.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
@Injectable()
export class SwPeopleService {
people$ = this.http.get('https://swapi.co/api/people/')
.map((res:any) => res.results);
constructor(private http: HttpClient) {}
}