|
| 1 | +var defaults = require('../../../lib/defaults'); |
| 2 | +var mergeConfig = require('../../../lib/core/mergeConfig'); |
| 3 | + |
| 4 | +describe('core::mergeConfig', function() { |
| 5 | + it('should accept undefined for second argument', function() { |
| 6 | + expect(mergeConfig(defaults, undefined)).toEqual(defaults); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should accept an object for second argument', function() { |
| 10 | + expect(mergeConfig(defaults, {})).toEqual(defaults); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should not leave references', function() { |
| 14 | + var merged = mergeConfig(defaults, {}); |
| 15 | + expect(merged).not.toBe(defaults); |
| 16 | + expect(merged.headers).not.toBe(defaults.headers); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should allow setting request options', function() { |
| 20 | + var config = { |
| 21 | + url: '__sample url__', |
| 22 | + method: '__sample method__', |
| 23 | + params: '__sample params__', |
| 24 | + data: { foo: true } |
| 25 | + }; |
| 26 | + var merged = mergeConfig(defaults, config); |
| 27 | + expect(merged.url).toEqual(config.url); |
| 28 | + expect(merged.method).toEqual(config.method); |
| 29 | + expect(merged.params).toEqual(config.params); |
| 30 | + expect(merged.data).toEqual(config.data); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should not inherit request options', function() { |
| 34 | + var localDefaults = { |
| 35 | + url: '__sample url__', |
| 36 | + method: '__sample method__', |
| 37 | + params: '__sample params__', |
| 38 | + data: { foo: true } |
| 39 | + }; |
| 40 | + var merged = mergeConfig(localDefaults, {}); |
| 41 | + expect(merged.url).toEqual(undefined); |
| 42 | + expect(merged.method).toEqual(undefined); |
| 43 | + expect(merged.params).toEqual(undefined); |
| 44 | + expect(merged.data).toEqual(undefined); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should merge auth, headers, proxy with defaults', function() { |
| 48 | + expect(mergeConfig({ auth: undefined }, { auth: { user: 'foo', pass: 'test' } })).toEqual({ |
| 49 | + auth: { user: 'foo', pass: 'test' } |
| 50 | + }); |
| 51 | + expect(mergeConfig({ auth: { user: 'foo', pass: 'test' } }, { auth: { pass: 'foobar' } })).toEqual({ |
| 52 | + auth: { user: 'foo', pass: 'foobar' } |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should overwrite auth, headers, proxy with a non-object value', function() { |
| 57 | + expect(mergeConfig({ auth: { user: 'foo', pass: 'test' } }, { auth: false })).toEqual({ |
| 58 | + auth: false |
| 59 | + }); |
| 60 | + expect(mergeConfig({ auth: { user: 'foo', pass: 'test' } }, { auth: null })).toEqual({ |
| 61 | + auth: null |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should allow setting other options', function() { |
| 66 | + var merged = mergeConfig(defaults, { timeout: 123 }); |
| 67 | + expect(merged.timeout).toEqual(123); |
| 68 | + }); |
| 69 | +}); |
0 commit comments