Skip to content

armgit / mocha

Public Imported from GitHub
0

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

always reference the correct it from it.only

Charles Lowell08bf74d8440b
diff --git a/Makefile b/Makefile
index 24bc89a2..28e6c87f 100644
--- a/Makefile
+++ b/Makefile
@@ -112,6 +112,11 @@ test-only:
--ui bdd \
test/acceptance/misc/only/bdd
+ @./bin/mocha \
+ --reporter $(REPORTER) \
+ --ui qunit \
+ test/acceptance/misc/only/bdd-require
+
@./bin/mocha \
--reporter $(REPORTER) \
--ui qunit \
diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js
index 253f24e4..42fcc744 100644
--- a/lib/interfaces/bdd.js
+++ b/lib/interfaces/bdd.js
@@ -77,7 +77,7 @@ module.exports = function(suite) {
* acting as a thunk.
*/
- context.it = context.specify = function(title, fn) {
+ var it = context.it = context.specify = function(title, fn) {
var suite = suites[0];
if (suite.pending) {
fn = null;
@@ -93,7 +93,7 @@ module.exports = function(suite) {
*/
context.it.only = function(title, fn) {
- var test = context.it(title, fn);
+ var test = it(title, fn);
var reString = '^' + escapeRe(test.fullTitle()) + '$';
mocha.grep(new RegExp(reString));
return test;
diff --git a/test/acceptance/misc/only/bdd-require.js b/test/acceptance/misc/only/bdd-require.js
new file mode 100644
index 00000000..516dad7a
--- /dev/null
+++ b/test/acceptance/misc/only/bdd-require.js
@@ -0,0 +1,18 @@
+/*jshint node: true */
+
+var mocha = require('../../../../lib/mocha');
+
+var beforeEach = mocha.beforeEach;
+var it = mocha.it;
+var describe = mocha.describe;
+
+describe('it.only via require("mocha")', function() {
+ beforeEach(function() {
+ this.didRunBeforeEach = true;
+ });
+ describe("nested within a describe/context", function() {
+ it.only('should run all enclosing beforeEach hooks', function() {
+ require('assert').equal(this.didRunBeforeEach, true);
+ });
+ });
+});