File tree 5 files changed +47
-2
lines changed
5 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ exports.create = function(parent, title) {
44
44
* @param {Context } parentContext
45
45
*/
46
46
function Suite ( title , parentContext ) {
47
+ if ( ! utils . isString ( title ) ) {
48
+ throw new Error ( 'Suite `title` should be a "string" but "' + typeof title + '" was given instead.' ) ;
49
+ }
47
50
this . title = title ;
48
51
function Context ( ) { }
49
52
Context . prototype = parentContext ;
Original file line number Diff line number Diff line change 4
4
5
5
var Runnable = require ( './runnable' ) ;
6
6
var create = require ( 'lodash.create' ) ;
7
+ var isString = require ( './utils' ) . isString ;
7
8
8
9
/**
9
10
* Expose `Test`.
@@ -19,6 +20,9 @@ module.exports = Test;
19
20
* @param {Function } fn
20
21
*/
21
22
function Test ( title , fn ) {
23
+ if ( ! isString ( title ) ) {
24
+ throw new Error ( 'Test `title` should be a "string" but "' + typeof title + '" was given instead.' ) ;
25
+ }
22
26
Runnable . call ( this , title , fn ) ;
23
27
this . pending = ! fn ;
24
28
this . type = 'test' ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ describe('a test that throws', function () {
7
7
var suite , runner ;
8
8
9
9
beforeEach ( function ( ) {
10
- suite = new Suite ( null , 'root' ) ;
10
+ suite = new Suite ( 'Suite' , 'root' ) ;
11
11
runner = new Runner ( suite ) ;
12
12
} )
13
13
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ describe('Runner', function(){
7
7
var suite , runner ;
8
8
9
9
beforeEach ( function ( ) {
10
- suite = new Suite ( null , 'root' ) ;
10
+ suite = new Suite ( 'Suite' , 'root' ) ;
11
11
runner = new Runner ( suite ) ;
12
12
} )
13
13
Original file line number Diff line number Diff line change @@ -393,4 +393,42 @@ describe('Suite', function(){
393
393
} ) ;
394
394
395
395
} ) ;
396
+
397
+ describe ( 'initialization' , function ( ) {
398
+ it ( 'should throw an error if the title isn\'t a string' , function ( ) {
399
+ ( function ( ) {
400
+ new Suite ( undefined , 'root' ) ;
401
+ } ) . should . throw ( ) ;
402
+
403
+ ( function ( ) {
404
+ new Suite ( function ( ) { } , 'root' ) ;
405
+ } ) . should . throw ( ) ;
406
+ } ) ;
407
+
408
+ it ( 'should not throw if the title is a string' , function ( ) {
409
+ ( function ( ) {
410
+ new Suite ( 'Bdd suite' , 'root' ) ;
411
+ } ) . should . not . throw ( ) ;
412
+ } ) ;
413
+ } ) ;
396
414
} ) ;
415
+
416
+ describe ( 'Test' , function ( ) {
417
+ describe ( 'initialization' , function ( ) {
418
+ it ( 'should throw an error if the title isn\'t a string' , function ( ) {
419
+ ( function ( ) {
420
+ new Test ( function ( ) { } ) ;
421
+ } ) . should . throw ( ) ;
422
+
423
+ ( function ( ) {
424
+ new Test ( undefined , function ( ) { } ) ;
425
+ } ) . should . throw ( ) ;
426
+ } ) ;
427
+
428
+ it ( 'should not throw if the title is a string' , function ( ) {
429
+ ( function ( ) {
430
+ new Test ( 'test-case' , function ( ) { } ) ;
431
+ } ) . should . not . throw ( ) ;
432
+ } ) ;
433
+ } ) ;
434
+ } ) ;
You can’t perform that action at this time.
0 commit comments