Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix(Suite/Test): untitled suite/test-case #1632

Ariel Mashraki7910a9208b71
diff --git a/lib/suite.js b/lib/suite.js
index d43dd456..74054dd0 100644
--- a/lib/suite.js
+++ b/lib/suite.js
@@ -41,6 +41,9 @@ exports.create = function(parent, title) {
* @param {Context} parentContext
*/
function Suite(title, parentContext) {
+ if (!utils.isString(title)) {
+ throw new Error('Suite `title` should be a "string" but "' + typeof title + '" was given instead.');
+ }
this.title = title;
function Context() {}
Context.prototype = parentContext;
diff --git a/lib/test.js b/lib/test.js
index a95cd31a..1e00c6f5 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -3,7 +3,8 @@
*/
var Runnable = require('./runnable');
-var inherits = require('./utils').inherits;
+var create = require('lodash.create');
+var isString = require('./utils').isString;
/**
* Expose `Test`.
@@ -19,6 +20,9 @@ module.exports = Test;
* @param {Function} fn
*/
function Test(title, fn) {
+ if (!isString(title)) {
+ throw new Error('Test `title` should be a "string" but "' + typeof title + '" was given instead.');
+ }
Runnable.call(this, title, fn);
this.pending = !fn;
this.type = 'test';
diff --git a/test/acceptance/throw.js b/test/acceptance/throw.js
index 1016a19e..46cfbad6 100644
--- a/test/acceptance/throw.js
+++ b/test/acceptance/throw.js
@@ -6,7 +6,7 @@ describe('a test that throws', function () {
var suite, runner;
beforeEach(function(){
- suite = new Suite(null, 'root');
+ suite = new Suite('Suite', 'root');
runner = new Runner(suite);
})
diff --git a/test/runner.js b/test/runner.js
index 7673a838..37aeb22d 100644
--- a/test/runner.js
+++ b/test/runner.js
@@ -7,7 +7,7 @@ describe('Runner', function(){
var suite, runner;
beforeEach(function(){
- suite = new Suite(null, 'root');
+ suite = new Suite('Suite', 'root');
runner = new Runner(suite);
})
diff --git a/test/suite.js b/test/suite.js
index 6588e248..7fead074 100644
--- a/test/suite.js
+++ b/test/suite.js
@@ -398,4 +398,42 @@ describe('Suite', function(){
});
});
+
+ describe('initialization', function() {
+ it('should throw an error if the title isn\'t a string', function() {
+ (function() {
+ new Suite(undefined, 'root');
+ }).should.throw();
+
+ (function() {
+ new Suite(function(){}, 'root');
+ }).should.throw();
+ });
+
+ it('should not throw if the title is a string', function() {
+ (function() {
+ new Suite('Bdd suite', 'root');
+ }).should.not.throw();
+ });
+ });
});
+
+describe('Test', function() {
+ describe('initialization', function() {
+ it('should throw an error if the title isn\'t a string', function() {
+ (function() {
+ new Test(function(){});
+ }).should.throw();
+
+ (function() {
+ new Test(undefined, function(){});
+ }).should.throw();
+ });
+
+ it('should not throw if the title is a string', function() {
+ (function() {
+ new Test('test-case', function(){});
+ }).should.not.throw();
+ });
+ });
+});
\ No newline at end of file