From e558697607f8d7466e7d6f8f1bbf0ed2eb8d1c0d Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 6 Feb 2018 14:23:48 -0500 Subject: [PATCH] Normalize arguments when using new. (#40) * Normalize arguments when using new. * lint --- packages/google-cloud-compute/src/index.js | 3 ++- packages/google-cloud-compute/test/index.js | 27 +++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/google-cloud-compute/src/index.js b/packages/google-cloud-compute/src/index.js index af8a3e19ef5..96642bc2151 100644 --- a/packages/google-cloud-compute/src/index.js +++ b/packages/google-cloud-compute/src/index.js @@ -78,10 +78,11 @@ var Zone = require('./zone.js'); */ function Compute(options) { if (!(this instanceof Compute)) { - options = common.util.normalizeArguments(this, options); return new Compute(options); } + options = common.util.normalizeArguments(this, options); + var config = { baseUrl: 'https://www.googleapis.com/compute/v1', scopes: ['https://www.googleapis.com/auth/compute'], diff --git a/packages/google-cloud-compute/test/index.js b/packages/google-cloud-compute/test/index.js index fddcd6a7bfc..6db6ce9f0b7 100644 --- a/packages/google-cloud-compute/test/index.js +++ b/packages/google-cloud-compute/test/index.js @@ -57,6 +57,7 @@ var fakeUtil = extend({}, util, { ]); }, }); +var originalFakeUtil = extend(true, {}, fakeUtil); var fakePaginator = { extend: function(Class, methods) { @@ -178,40 +179,36 @@ describe('Compute', function() { }); beforeEach(function() { + extend(fakeUtil, originalFakeUtil); compute = new Compute({ projectId: PROJECT_ID, }); }); describe('instantiation', function() { - var options = { - projectId: PROJECT_ID, - credentials: 'credentials', - email: 'email', - keyFilename: 'keyFile', - }; - it('should return a new instance of Compute', function() { var compute = new Compute({projectId: PROJECT_ID}); assert(compute instanceof Compute); }); + it('should work without new', function() { + assert.doesNotThrow(function() { + Compute({projectId: PROJECT_ID}); + }); + }); + it('should normalize the arguments', function() { - var normalizeArguments = fakeUtil.normalizeArguments; var normalizeArgumentsCalled = false; - var fakeContext = {}; + var options = {}; fakeUtil.normalizeArguments = function(context, options_) { normalizeArgumentsCalled = true; - assert.strictEqual(context, fakeContext); - assert.strictEqual(options, options_); + assert.strictEqual(options_, options); return options_; }; - Compute.call(fakeContext, options); - assert(normalizeArgumentsCalled); - - fakeUtil.normalizeArguments = normalizeArguments; + new Compute(options); + assert.strictEqual(normalizeArgumentsCalled, true); }); it('should inherit from Service', function() {