From f87178241fc74a54739497a5f1faedbf1cab5e76 Mon Sep 17 00:00:00 2001 From: Arvid Ottenberg Date: Tue, 5 May 2020 23:44:23 +0200 Subject: [PATCH] throw exception if --forbid-only option is set even if suite is not selected by grep --- lib/interfaces/common.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/interfaces/common.js b/lib/interfaces/common.js index e7e84b2511..53c8d8c26c 100644 --- a/lib/interfaces/common.js +++ b/lib/interfaces/common.js @@ -93,6 +93,9 @@ module.exports = function(suites, context, mocha) { * @returns {Suite} */ only: function only(opts) { + if (mocha.options.forbidOnly) { + throw createUnsupportedError('`.only` forbidden'); + } opts.isOnly = true; return this.create(opts); }, @@ -126,11 +129,7 @@ module.exports = function(suites, context, mocha) { suite.file = opts.file; suites.unshift(suite); if (opts.isOnly) { - if (mocha.options.forbidOnly && shouldBeTested(suite)) { - throw createUnsupportedError('`.only` forbidden'); - } - - suite.parent.appendOnlySuite(suite); + suite.markOnly(); } if (suite.pending) { if (mocha.options.forbidPending && shouldBeTested(suite)) {