I do want to create test data in the beforeEach
method and access that data to give to the parameterized test but I get an error TS2454: Variable testData is used before being assigned.
describe('Test', async () => {
let testProduct: Product
beforeEach(async () => {
testData = await createUser();
})
[
{ input: testProduct.id, error: false }, // TS2454: Variable testData is used before being assigned
{ input: "Non Existent", error: true },
].forEach(({ input, error }) =>
it('Test Query', async () => {
const client = createApolloTestClient();
const res = await client.query<{userFound: boolean}, {id: string}>({
query: ProductQuery,
variables: {id: input}
});
expect(res.data?.userFound).toBe(error)
}))
})
How can I refactor this to make it work?