I have this test:
describe('Ao iniciar uma entrevista por id', function () {
it('deve deve utilizar diretorio raiz da aplicacao', inject(function (Questionario) {
expect(Questionario.urlEntrevistaPorId).toContain(raiz);
}));
it('deve atualizar modelo', inject(function (Questionario, $httpBackend) {
var entrevistaNova = { a: 1, b: 2 };
$httpBackend.expectPUT(Questionario.urlEntrevistaPorId, { estudoId: idEstudo, entrevistaId: 666 }).respond({
Entrevista: entrevistaNova,
PaginaAtual: novaPagina
});
Questionario.iniciarEntrevista(666);
spyOn(Questionario, 'setEntrevista');
$httpBackend.flush();
expect(Questionario.setEntrevista).toHaveBeenCalledWith(entrevistaNova, novaPagina);
}));
});
function iniciarEntrevista(id) {
var _this = this;
return $http
.put(this.urlEntrevistaPorId, { estudoId: idEstudo, entrevistaId: id })
.success(function (result) {
if (result.Iniciada) {
_this.setEntrevista(result.Entrevista, result.PaginaAtual);
return true;
}
else {
return false;
}
});
}
Which calls Questionario.iniciarEntrevista and waits for setEntrevista to be called. But this method is not being called because of the return of the $http.put.
I need result.Iniciada to be true.
How do I mock this?
Aucun commentaire:
Enregistrer un commentaire