Skip to content

Commit 5fcda8e

Browse files
Normalize arguments when using new. (#19)
1 parent 2bb3db6 commit 5fcda8e

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

packages/google-cloud-dns/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ var Zone = require('./zone.js');
8080
*/
8181
function DNS(options) {
8282
if (!(this instanceof DNS)) {
83-
options = common.util.normalizeArguments(this, options);
8483
return new DNS(options);
8584
}
8685

86+
options = common.util.normalizeArguments(this, options);
87+
8788
var config = {
8889
baseUrl: 'https://www.googleapis.com/dns/v1',
8990
scopes: [

packages/google-cloud-dns/test/index.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var fakeUtil = extend({}, util, {
6060
assert.deepEqual(options.exclude, ['zone']);
6161
},
6262
});
63+
var originalFakeUtil = extend(true, {}, fakeUtil);
6364

6465
function FakeZone() {
6566
this.calledWith_ = arguments;
@@ -83,6 +84,7 @@ describe('DNS', function() {
8384
});
8485

8586
beforeEach(function() {
87+
extend(fakeUtil, originalFakeUtil);
8688
dns = new DNS({
8789
projectId: PROJECT_ID,
8890
});
@@ -101,23 +103,24 @@ describe('DNS', function() {
101103
assert(promisified);
102104
});
103105

106+
it('should work without new', function() {
107+
assert.doesNotThrow(function() {
108+
DNS({projectId: PROJECT_ID});
109+
});
110+
});
111+
104112
it('should normalize the arguments', function() {
105-
var normalizeArguments = fakeUtil.normalizeArguments;
106113
var normalizeArgumentsCalled = false;
107-
var fakeOptions = {projectId: PROJECT_ID};
108-
var fakeContext = {};
114+
var options = {};
109115

110-
fakeUtil.normalizeArguments = function(context, options) {
116+
fakeUtil.normalizeArguments = function(context, options_) {
111117
normalizeArgumentsCalled = true;
112-
assert.strictEqual(context, fakeContext);
113-
assert.strictEqual(options, fakeOptions);
114-
return options;
118+
assert.strictEqual(options_, options);
119+
return options_;
115120
};
116121

117-
DNS.call(fakeContext, fakeOptions);
118-
assert(normalizeArgumentsCalled);
119-
120-
fakeUtil.normalizeArguments = normalizeArguments;
122+
new DNS(options);
123+
assert.strictEqual(normalizeArgumentsCalled, true);
121124
});
122125

123126
it('should inherit from Service', function() {

0 commit comments

Comments
 (0)