File tree Expand file tree Collapse file tree 5 files changed +47
-2
lines changed
Expand file tree Collapse file tree 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) {
4444 * @param {Context } parentContext
4545 */
4646function 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+ }
4750 this . title = title ;
4851 function Context ( ) { }
4952 Context . prototype = parentContext ;
Original file line number Diff line number Diff line change 44
55var Runnable = require ( './runnable' ) ;
66var create = require ( 'lodash.create' ) ;
7+ var isString = require ( './utils' ) . isString ;
78
89/**
910 * Expose `Test`.
@@ -19,6 +20,9 @@ module.exports = Test;
1920 * @param {Function } fn
2021 */
2122function Test ( title , fn ) {
23+ if ( ! isString ( title ) ) {
24+ throw new Error ( 'Test `title` should be a "string" but "' + typeof title + '" was given instead.' ) ;
25+ }
2226 Runnable . call ( this , title , fn ) ;
2327 this . pending = ! fn ;
2428 this . type = 'test' ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ describe('a test that throws', function () {
77 var suite , runner ;
88
99 beforeEach ( function ( ) {
10- suite = new Suite ( null , 'root' ) ;
10+ suite = new Suite ( 'Suite' , 'root' ) ;
1111 runner = new Runner ( suite ) ;
1212 } )
1313
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ describe('Runner', function(){
77 var suite , runner ;
88
99 beforeEach ( function ( ) {
10- suite = new Suite ( null , 'root' ) ;
10+ suite = new Suite ( 'Suite' , 'root' ) ;
1111 runner = new Runner ( suite ) ;
1212 } )
1313
Original file line number Diff line number Diff line change @@ -393,4 +393,42 @@ describe('Suite', function(){
393393 } ) ;
394394
395395 } ) ;
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+ } ) ;
396414} ) ;
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