FjordWarden
FjordWarden13mo ago

BDD with async tests

I'd like to run some tests that all call the same helper function that wraps the bdd it function. Something like this:
describe('why u no work?', async ()=>{
const test = async (s) => {let r = await Promise.resolve(0); it(s, ()=>assertEquals(0,r))}
await test('a')
await test('b')
await test('c')
})
describe('why u no work?', async ()=>{
const test = async (s) => {let r = await Promise.resolve(0); it(s, ()=>assertEquals(0,r))}
await test('a')
await test('b')
await test('c')
})
It works with a non-async version but I'd like to know how to do this in a async way.
2 Replies
Deno AI Helper
Deno AI Helper13mo ago
Based on the documentation, Deno's built-in test runner supports both synchronous and asynchronous tests. However, the describe and it functions you're using are not part of Deno's built-in testing tools. They are commonly used in JavaScript testing libraries like Mocha or Jasmine. In Deno, you would use Deno.test to define a test. If your test function is asynchronous, the test runner will await its resolution to consider the test complete. Here's how you might write your tests in Deno:
const test = async (s: string) => {
let r = await Promise.resolve(0);
Deno.test(s, () => assertEquals(0, r));
};

await test('a');
await test('b');
await test('c');
const test = async (s: string) => {
let r = await Promise.resolve(0);
Deno.test(s, () => assertEquals(0, r));
};

await test('a');
await test('b');
await test('c');
Each call to test creates a new test case that will be run when you use deno test on the command line. The test function can be async, and Deno will automatically handle awaiting its resolution. Please note that this information is based on the Deno documentation and may not apply if you're using a different testing library or framework.
FjordWarden
FjordWarden13mo ago
Sorry but this AI is stupid, I am asking about the funciton in the deno std