Skip to content

Commit

Permalink
Merge pull request #118 from miksago/add-tests-for-defaults
Browse files Browse the repository at this point in the history
Add tests for defaults
  • Loading branch information
geek committed Mar 2, 2016
2 parents d049fa7 + dcd0307 commit 289fd7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -66,7 +66,7 @@ internals.resolveUrl = function (baseUrl, path) {

internals.Client.prototype.request = function (method, url, options, callback, _trace) {

options = Hoek.applyToDefaultsWithShallow(options || {}, this._defaults, internals.shallowOptions);
options = Hoek.applyToDefaultsWithShallow(this._defaults, options || {}, internals.shallowOptions);

Hoek.assert(options.payload === null || options.payload === undefined || typeof options.payload === 'string' ||
options.payload instanceof Stream || Buffer.isBuffer(options.payload),
Expand Down
19 changes: 19 additions & 0 deletions test/index.js
Expand Up @@ -1957,6 +1957,9 @@ describe('Events', () => {
});
});
});
});

describe('Defaults', () => {

it('rejects attempts to use defaults without an options hash', (done) => {

Expand Down Expand Up @@ -2002,4 +2005,20 @@ describe('Events', () => {
});
});
});

it('applies defaults correctly to requests', (done) => {

const optionsA = { headers: { Accept: 'foo', 'Test': 123 } };
const optionsB = { headers: { Accept: 'bar' } };

const wreckA = Wreck.defaults(optionsA);

const req1 = wreckA.request('get', 'http://localhost/', optionsB, (err) => {

expect(req1._headers.accept).to.equal('bar');
expect(req1._headers.test).to.equal(123);

done();
});
});
});

0 comments on commit 289fd7a

Please sign in to comment.