Skip to content

Commit 5c4191a

Browse files
tests: fix assert.throws() usage
1 parent 143f120 commit 5c4191a

14 files changed

Lines changed: 43 additions & 53 deletions

File tree

packages/compute/test/zone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe('Zone', function() {
182182
it('should throw if a target is not provided', function() {
183183
assert.throws(function() {
184184
zone.createAutoscaler(NAME, {}, assert.ifError);
185-
}, 'Cannot create an autoscaler without a target.');
185+
}, /Cannot create an autoscaler without a target\./);
186186
});
187187

188188
it('should make the correct request', function(done) {

packages/datastore/test/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ describe('Request', function() {
13051305

13061306
assert.throws(function() {
13071307
request.request_({ method: 'runQuery' }, reqOpts, assert.ifError);
1308-
}, 'Read consistency cannot be specified in a transaction.');
1308+
}, /Read consistency cannot be specified in a transaction\./);
13091309
});
13101310
});
13111311
});

packages/logging/test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ describe('Logging', function() {
170170
it('should throw if a name is not provided', function() {
171171
assert.throws(function() {
172172
logging.createSink();
173-
}, 'A sink name must be provided.');
173+
}, /A sink name must be provided\./);
174174
});
175175

176176
it('should throw if a config object is not provided', function() {
177177
assert.throws(function() {
178178
logging.createSink(SINK_NAME);
179-
}, 'A sink configuration object must be provided.');
179+
}, /A sink configuration object must be provided\./);
180180
});
181181

182182
it('should set acls for a Bucket destination', function(done) {

packages/prediction/test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Prediction', function() {
128128
it('should throw if a model ID is not provided', function() {
129129
assert.throws(function() {
130130
prediction.createModel();
131-
}, /A model ID is required/);
131+
}, /A model ID is required\./);
132132
});
133133

134134
it('should make the correct API request', function(done) {
@@ -379,7 +379,7 @@ describe('Prediction', function() {
379379
it('should throw if a name is not provided', function() {
380380
assert.throws(function() {
381381
prediction.model();
382-
}, /A model ID is required/);
382+
}, /A model ID is required\./);
383383
});
384384

385385
it('should return a Model', function() {

packages/pubsub/test/iam.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('IAM', function() {
9393
it('should throw an error if a policy is not supplied', function() {
9494
assert.throws(function() {
9595
iam.setPolicy(util.noop);
96-
}, /A policy object is required/);
96+
}, /A policy object is required\./);
9797
});
9898

9999
it('should make the correct API request', function(done) {
@@ -117,7 +117,7 @@ describe('IAM', function() {
117117
it('should throw an error if permissions are missing', function() {
118118
assert.throws(function() {
119119
iam.testPermissions(util.noop);
120-
}, /Permissions are required/);
120+
}, /Permissions are required\./);
121121
});
122122

123123
it('should make the correct API request', function(done) {

packages/pubsub/test/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ describe('PubSub', function() {
468468
it('should throw if no Topic is provided', function() {
469469
assert.throws(function() {
470470
pubsub.subscribe();
471-
}, /A Topic is required.*/);
471+
}, /A Topic is required for a new subscription\./);
472472
});
473473

474474
it('should throw if no sub name is provided', function() {
475475
assert.throws(function() {
476476
pubsub.subscribe('topic');
477-
}, /A subscription name is required.*/);
477+
}, /A subscription name is required for a new subscription\./);
478478
});
479479

480480
it('should not require configuration options', function(done) {
@@ -680,7 +680,7 @@ describe('PubSub', function() {
680680
it('should throw if no name is provided', function() {
681681
assert.throws(function() {
682682
pubsub.subscription();
683-
}, /The name of a subscription is required/);
683+
}, /The name of a subscription is required\./);
684684
});
685685

686686
it('should return a Subscription object', function() {
@@ -716,7 +716,7 @@ describe('PubSub', function() {
716716
it('should throw if a name is not provided', function() {
717717
assert.throws(function() {
718718
pubsub.topic();
719-
}, /name must be specified/);
719+
}, /A name must be specified for a new topic\./);
720720
});
721721

722722
it('should return a Topic object', function() {

packages/pubsub/test/subscription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ describe('Subscription', function() {
258258
it('should throw if no IDs are provided', function() {
259259
assert.throws(function() {
260260
subscription.ack();
261-
}, /At least one ID/);
261+
}, /At least one ID must be specified before it can be acknowledged\./);
262262
assert.throws(function() {
263263
subscription.ack([]);
264-
}, /At least one ID/);
264+
}, /At least one ID must be specified before it can be acknowledged\./);
265265
});
266266

267267
it('should accept a single id', function() {

packages/pubsub/test/topic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,17 @@ describe('Topic', function() {
185185
it('should throw if no message is provided', function() {
186186
assert.throws(function() {
187187
topic.publish();
188-
}, /Cannot publish without a message/);
188+
}, /Cannot publish without a message\./);
189189

190190
assert.throws(function() {
191191
topic.publish([]);
192-
}, /Cannot publish without a message/);
192+
}, /Cannot publish without a message\./);
193193
});
194194

195195
it('should throw if a message has no data', function() {
196196
assert.throws(function() {
197197
topic.publish({});
198-
}, /Cannot publish message without a `data` property/);
198+
}, /Cannot publish message without a `data` property\./);
199199
});
200200

201201
it('should send correct api request', function(done) {

packages/resource/test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ describe('Resource', function() {
327327

328328
assert.throws(function() {
329329
resourceWithoutProjectId.project();
330-
}, /A project ID is required/);
330+
}, /A project ID is required\./);
331331
});
332332
});
333333
});

packages/storage/test/bucket.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,19 @@ describe('Bucket', function() {
194194

195195
describe('combine', function() {
196196
it('should throw if invalid sources are not provided', function() {
197-
var error = 'You must provide at least two source files.';
198-
199197
assert.throws(function() {
200198
bucket.combine();
201-
}, new RegExp(error));
199+
}, /You must provide at least two source files\./);
202200

203201
assert.throws(function() {
204202
bucket.combine(['1']);
205-
}, new RegExp(error));
203+
}, /You must provide at least two source files\./);
206204
});
207205

208206
it('should throw if a destination is not provided', function() {
209-
var error = 'A destination file must be specified.';
210-
211207
assert.throws(function() {
212208
bucket.combine(['1', '2']);
213-
}, new RegExp(error));
209+
}, /A destination file must be specified\./);
214210
});
215211

216212
it('should accept string or file input for sources', function(done) {
@@ -292,7 +288,7 @@ describe('Bucket', function() {
292288
it('should throw if content type cannot be determined', function() {
293289
assert.throws(function() {
294290
bucket.combine(['1', '2'], 'destination');
295-
}, /A content type could not be detected/);
291+
}, /A content type could not be detected for the destination file\./);
296292
});
297293

298294
it('should make correct API request', function(done) {
@@ -395,13 +391,13 @@ describe('Bucket', function() {
395391
it('should throw if an ID is not provided', function() {
396392
assert.throws(function() {
397393
bucket.createChannel();
398-
}, 'An ID is required to create a channel.');
394+
}, /An ID is required to create a channel\./);
399395
});
400396

401397
it('should throw if an address is not provided', function() {
402398
assert.throws(function() {
403399
bucket.createChannel(ID, {});
404-
}, 'An address is required to create a channel.');
400+
}, /An address is required to create a channel\./);
405401
});
406402

407403
it('should make the correct request', function(done) {
@@ -607,7 +603,7 @@ describe('Bucket', function() {
607603
it('should throw if no name is provided', function() {
608604
assert.throws(function() {
609605
bucket.file();
610-
}, /A file name must be specified/);
606+
}, /A file name must be specified\./);
611607
});
612608

613609
it('should return a File object', function() {

0 commit comments

Comments
 (0)