如何在 Jest 中循环遍历动态测试用例?
我有以下这样的测试用例,我如何使用 it/test
方法动态地创建测试用例。
下面是我尝试过的 ,但是它只是通过而不执行循环中的测试用例。
const mymodule = require('mymodule');
const testCases = [
{q: [2, 3],r: 5},
{q: [1, 2],r: 3},
{q: [7, 0],r: 7},
{q: [4, 4],r: 8}
];
describe("Test my Math module", () => {
test("test add method", () => {
for (let i = 0; i < testCases.length; i++) {
const { q,r } = testCases[i];
it(`should add ${q[0]},${q[1]} to ${expected}`, () => {
const actual = mymodule.add(q[0] + q[1]);
expect(actual).toBe(expected);
});
}
});
});