-
Notifications
You must be signed in to change notification settings - Fork 632
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
bdd testing: easy testing of arrays #3268
Comments
You can call it or describe in a for loop or a forEach block. Here is an example based on code samples you provided. In it, it will register a test group for each category with names in the format data.categories.forEach((category, index) => {
describe(`category[${index}]`, () => {
it("name", () => {
assert(category.name.length > 0);
});
it("params", () => {
assert(category.params.length > 0);
});
});
}); If you have tests you only want to run for specific types of category objects, you could use if blocks to conditionally register different types of tests. And it doesn't all have to be in a single for loop or forEach, you could create functions for registering sets of tests then conditionally call them. The describe/it function's are pretty flexible. I would personally prefer not adding something like the 2 examples provided. I believe it would make it more confusing to read and write test cases. In your first example, one might miss that there is a generator in their beforeAll when reading the test cases. For both examples, I'd have another question, which is what would the names for each of those cases generated? With the example I wrote, I believe it's much more clear how the test cases are being registered and what the names will be. |
I can't do I haven't found a way to load |
Why is data not available at top-level, but available at Have you tried |
I don't remember the reason anymore, but I believe it's because if you It's been some time since I last touched this, but I also think Deno was complaining about data not being cleaned up or similar. |
Thanks for your reply. I'm closing this issue for now because you don't seem needing it anymore. Please re-open this issue or create a new one if you find a similar situation, and still find this is an issue |
Is your feature request related to a problem? Please describe.
Yes. currently, it's not very easy to test arrays of data. For example, I'm writing a library that parses (rather complex) musical data into reusable JSON structures.
Take this example:
this is how I'm testing this currently
Describe the solution you'd like
It would be nice if for example the
describe
function could take in arrays I'm not sure (or an iterator).or maybe something attached to describe
Describe alternatives you've considered
I've tried many alternatives, but no one really worked. right now I'm just using asserts (hence throwing away the benefits of bdd
The text was updated successfully, but these errors were encountered: