/
hello-world.service.spec.pact.ts
49 lines (44 loc) · 1.51 KB
/
hello-world.service.spec.pact.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import '@angular/compiler';
import { HttpClientModule } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';
import { pactWith } from 'jest-pact';
import { HelloWorldService } from './hello-world.service';
import { HttpTestingController } from '@angular/common/http/testing';
pactWith({
consumer: 'angular-plain-2',
provider: 'HellowWorldService'}, provider => {
let service: HelloWorldService;
let httpMock: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [HelloWorldService, HttpTestingController],
});
service = TestBed.inject(HelloWorldService);
httpMock = TestBed.inject(HttpTestingController);
});
describe('Welcome to api', () => {
beforeEach(() => provider.addInteraction({
state: 'server is healthy',
uponReceiving: 'A request for API',
willRespondWith: {
status: 200,
body: {
message: 'Welcome to api!'
},
},
withRequest: {
method: 'GET',
path: '/hello'
}
}));
it('returns Welcome to api!', async () => {
service.helloWorld(provider.mockService.baseUrl).subscribe((res) => {
console.log("res", res);
expect(res).toEqual({
'message': 'Welcome to api!'
})
});
})
});
})