summaryrefslogtreecommitdiff
path: root/axios/test/specs/utils/extend.spec.js
blob: 3e1bb32ff1726ef49b0a25a9615b6fb0071ba0b7 (plain)
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
var extend = require('../../../lib/utils').extend;

describe('utils::extend', function () {
  it('should be mutable', function () {
    var a = {};
    var b = {foo: 123};

    extend(a, b);

    expect(a.foo).toEqual(b.foo);
  });
  
  it('should extend properties', function () {
    var a = {foo: 123, bar: 456};
    var b = {bar: 789};

    a = extend(a, b);

    expect(a.foo).toEqual(123);
    expect(a.bar).toEqual(789);
  });

  it('should bind to thisArg', function () {
    var a = {};
    var b = {getFoo: function getFoo() { return this.foo; }};
    var thisArg = { foo: 'barbaz' };

    extend(a, b, thisArg);

    expect(typeof a.getFoo).toEqual('function');
    expect(a.getFoo()).toEqual(thisArg.foo);
  });
});