-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathunleash-client.spec.ts
54 lines (44 loc) · 1.36 KB
/
unleash-client.spec.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
50
51
52
53
54
import { HttpModule, HttpService } from '@nestjs/axios'
import { Test, TestingModule } from '@nestjs/testing'
import { of } from 'rxjs'
import { UnleashClient } from './unleash-client'
describe('UnleashClient', () => {
let client: UnleashClient
let requestSpy: jest.SpyInstance
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
HttpModule.register({
baseURL: 'https://example.com/',
headers: {
'UNLEASH-INSTANCEID': 'MY-INSTANCE-ID',
},
}),
],
providers: [UnleashClient],
}).compile()
client = module.get(UnleashClient)
requestSpy = jest
.spyOn(module.get(HttpService), 'request')
.mockImplementation()
})
it('request()', async () => {
requestSpy.mockReturnValue(of({ data: { a: 'b' } }))
expect(await client.request({ method: 'GET', url: '/foo' })).toEqual({
a: 'b',
})
expect(requestSpy).toHaveBeenCalledWith({ method: 'GET', url: '/foo' })
})
it('get()', async () => {
await client.get('/test')
expect(requestSpy).toHaveBeenCalledWith({ method: 'GET', url: '/test' })
})
it('post()', async () => {
await client.post('/test', { my: 'data' })
expect(requestSpy).toHaveBeenCalledWith({
data: { my: 'data' },
method: 'POST',
url: '/test',
})
})
})