Danielduel
Danielduel3w ago

Deno.test with "each" support

I tried to find in docs if something like https://deno.land/x/test_each@v0.0.2 or jest's https://jestjs.io/docs/api#each exists in Deno.test Looks like it is not, if you know that I missed something or there's a common pattern of doing this in Deno.test (like idk... mapping an array into an array of asserts and somehow getting the correct message out - please steer me into the correct direction.
Globals · Jest
In your test files, Jest puts each of these methods and objects into the global environment. You don't have to require or import anything to use them. However, if you prefer explicit imports, you can do import {describe, expect, test} from '@jest/globals'.
1 Reply
Deno AI Helper
I wasn't able to find the answer to your question in the official Deno documentation regarding a feature similar to test.each in Jest or the test_each module in Deno. However, based on your message, if you're looking to implement a pattern where you map an array into an array of tests, you could consider using Deno's standard testing API to loop over an array of test cases and create a test for each one. Here's a basic example of how you might do that:
const testCases = [
{ input: 'input1', expected: 'expected1' },
{ input: 'input2', expected: 'expected2' },
// ... other test cases
];

for (const testCase of testCases) {
Deno.test(`test for input: ${testCase.input}`, () => {
const result = yourFunction(testCase.input);
assertEquals(result, testCase.expected);
});
}
const testCases = [
{ input: 'input1', expected: 'expected1' },
{ input: 'input2', expected: 'expected2' },
// ... other test cases
];

for (const testCase of testCases) {
Deno.test(`test for input: ${testCase.input}`, () => {
const result = yourFunction(testCase.input);
assertEquals(result, testCase.expected);
});
}
This isn't based on the Deno documentation, so please double-check the accuracy of this advice. You can also explore community resources or forums for common patterns that other developers might be using for this kind of testing in Deno.