-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathconfig.spec.ts
More file actions
51 lines (45 loc) · 1.79 KB
/
config.spec.ts
File metadata and controls
51 lines (45 loc) · 1.79 KB
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
import 'jest';
import fs from 'fs';
import path from 'path';
import * as Config from './config';
describe('Config', () => {
afterEach(() => {
jest.restoreAllMocks();
});
it('get: should return cached config if force set to false', () => {
const cachedConfigTest = {};
const getCachedConfigMock = jest.spyOn(Config, 'getCachedConfig').mockReturnValue(cachedConfigTest);
const getUserSettingsSpy = jest.spyOn(Config, 'getUserSettings');
const config = Config.get(false);
expect(getCachedConfigMock).toHaveBeenCalled();
expect(config).toBe(cachedConfigTest);
expect(getUserSettingsSpy).not.toHaveBeenCalled();
});
it('get: should return default settings values when no user settings provided', () => {
jest.spyOn(Config, 'getUserSettings').mockImplementation(() => {
return {};
});
const maxSyncs = Config.get(true).maxSyncs;
expect(maxSyncs).toBe(5242);
});
it('get: should return user settings values when user settings provided', () => {
const maxSyncsTestVal = 9999;
jest.spyOn(Config, 'getUserSettings').mockReturnValue({
maxSyncs: maxSyncsTestVal,
});
const maxSyncs = Config.get(true).maxSyncs;
expect(maxSyncs).toStrictEqual(maxSyncsTestVal);
});
it('get: should return package version number', () => {
const versionTestVal = '1.1.1';
jest.spyOn(Config, 'getPackageVersion').mockReturnValue(versionTestVal);
const version = Config.get(true).version;
expect(version).toStrictEqual(versionTestVal);
});
it('getUserSettings: should return an empty object if no user settings exist', () => {
jest.spyOn(path, 'join').mockReturnValue(null);
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
const userSettings = Config.getUserSettings(null);
expect(userSettings).toStrictEqual({});
});
});