-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you generate dynamic suites with describe()? #4126
Comments
I have never used dynamics suites before, so I don't really know. It's Friday, 13th and my feeling tells me we should not open this coffin, but anyway ... You should really be sure, that all this effort is worth while. Maybe you could set your various I'm quite sure your examples will not work using Your last proposition seems to work, so you have to try and see. function mySuite(name) {
const suite = Mocha.Suite.create(this, 'mySuite:' + global.value + ': ' + name);
suite.addTest(it('should pass', function() {}));
return suite;
}
describe('ONE', function() {
let suiteOne = this;
before(function() {
global.value = 'ONE';
mySuite.call(suiteOne, 'this runs the suite once with success');
});
it('', function() {});
});
|
Thanks @juergba! I don't particularly like it, but I'm currently passing in a function to |
@plasticrake is there a reason you need to set The |
I am a bot that watches issues for inactivity. |
Meanwhile I don't think this is a good way to dynamically create tests. Our interface has not been designed for iterative parsing/runner-creation and tests execution. We should think about extending our programmatic API and exposing some (new) functions like |
I'm trying to dynamically generate suites based on examples I've seen generating tests using
it()
andaddTest()
. However usingdescribe()
seems to do something behind the scenes that doesn't work the same way.My actual use case is more complicated. I need to be able to have
mySuite()
be run as-is, but then also be able to add it to other suites as well. However I can't figure out how to get it inside the context of another suite properly.How can I place
mySuite()
inside another describe block while not losing it's context?Output:
I can get it to work with
mySuite
written like this:However I don't like this clunky syntax, and I may have lots of nested suites/describes. Is there a better way?
The text was updated successfully, but these errors were encountered: