-
Notifications
You must be signed in to change notification settings - Fork 6
/
get.spec.ts
43 lines (39 loc) · 1.14 KB
/
get.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
jest.mock('../../lib/config/config');
jest.mock('../../hooks/analytics/analytics');
jest.mock('../../hooks/prerun/prerun');
import {mocked} from 'ts-jest/utils';
import {Config} from '../../lib/config/config';
import {test} from '@oclif/test';
const mockedConfig = mocked(Config);
describe('config:get', () => {
const mockGet = jest.fn();
const mockSet = jest.fn();
beforeEach(() => {
mockedConfig.mockImplementation(
() =>
({
get: mockGet,
set: mockSet,
} as unknown as Config)
);
});
test
.do(() => {
mockGet.mockReturnValueOnce({foo: 'bar', buzz: 'bazz'});
})
.stdout()
.command(['config:get'])
.it('prints the config', (ctx) => {
expect(JSON.parse(ctx.stdout)).toMatchObject({foo: 'bar', buzz: 'bazz'});
});
test
.do(() => {
mockGet.mockReturnValueOnce({accessToken: 'oh no', foo: 'bar'});
})
.stdout()
.command(['config:get'])
.it('prints the config by omitting access token', (ctx) => {
expect(JSON.parse(ctx.stdout)).not.toHaveProperty('accessToken');
expect(JSON.parse(ctx.stdout)).toHaveProperty('foo');
});
});