-
Notifications
You must be signed in to change notification settings - Fork 851
/
config-factory.spec.ts
75 lines (60 loc) · 1.9 KB
/
config-factory.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { createConfig } from '../../src/config-factory';
describe('configFactory', () => {
let result;
// var createConfig = configFactory.createConfig;
describe('createConfig()', () => {
describe('classic config', () => {
const context = '/api';
const options = { target: 'http://www.example.org' };
beforeEach(() => {
result = createConfig(context, options);
});
it('should return config object', () => {
expect(Object.keys(result)).toEqual(['context', 'options']);
});
it('should return config object with context', () => {
expect(result.context).toBe(context);
});
it('should return config object with options', () => {
expect(result.options).toEqual(options);
});
});
describe('Object config', () => {
beforeEach(() => {
result = createConfig({ target: 'http://www.example.org:8000' });
});
it('should set the proxy path to everything', () => {
expect(result.context).toBe('/');
});
it('should return config object', () => {
expect(result.options).toEqual({
target: 'http://www.example.org:8000',
});
});
});
describe('missing option.target', () => {
let fn;
beforeEach(() => {
fn = () => {
createConfig('/api');
};
});
it('should throw an error when target and router option are missing', () => {
expect(fn).toThrowError(Error);
});
});
describe('optional option.target when option.router is used', () => {
let fn;
beforeEach(() => {
fn = () => {
createConfig('/api', {
router: (req) => 'http://www.example.com',
});
};
});
it('should not throw an error when target option is missing when router is used', () => {
expect(fn).not.toThrowError(Error);
});
});
});
});