Last active
March 5, 2019 10:43
-
-
Save wiemKh/07bbdf04e8e39e748bcb41425b7dd4dd to your computer and use it in GitHub Desktop.
unit testing service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TestBed, async, inject } from '@angular/core/testing'; | |
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | |
import { HttpClientModule, HttpClient } from '@angular/common/http'; | |
import { ProfileService } from './profile.service'; | |
import { of } from 'rxjs'; | |
describe('ProfileService', () => { | |
beforeEach(async () => TestBed.configureTestingModule({ | |
providers: [ProfileService], | |
imports: [HttpClientTestingModule] | |
})); | |
let service; | |
let http; | |
let backend; | |
beforeEach(inject([ProfileService, HttpClient, HttpTestingController], (_s: ProfileService, _h: HttpClient, | |
_b: HttpTestingController) => { | |
service = _s; | |
http = _h; | |
backend = _b; | |
})); | |
afterEach(inject([HttpTestingController], (httpMock: HttpTestingController) => { | |
httpMock.verify(); | |
})); | |
it('should update profile', () => { | |
let service: ProfileService = TestBed.get(ProfileService); | |
let httpTestingController = TestBed.get(HttpTestingController); | |
let mockProfile = { | |
"Nom": "Eric1", | |
"Nom_entreprise": "entreprise", | |
"Prenom": "BEN ARBIAA", | |
"email": "[email protected]", | |
"tel_fixe": "777777778", | |
"tel_port": "999999999781118" | |
} | |
service.updateProfile(mockProfile).subscribe(data => { | |
expect(data.Nom).toEqual("Eric1"); | |
}); | |
const req = httpTestingController.expectOne('http://localhost:3000/api/profile/'); | |
expect(req.request.method).toBe('PUT'); | |
req.flush( mockProfile); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment