Is it possible to reuse "it" in nested test? #23716
Answered
by
emilyrohrbough
iamyoki
asked this question in
Questions and Help
-
Say I have 3 second tabs under every primary tabs, and I have wrote those 2 tests: describe('Nested tabs', () => {
it('swtich primary tabs', () => {
primaryTabs.forEach((t) => {
cy.contains(t).click();
});
});
it('swtich second tabs', () => {
secondTabs.forEach((t) => {
cy.contains(t).click();
});
});
}); But that's not covering all clickable scenarios, what I want to achieve is like this: describe('Nested tabs', () => {
it('swtich primary tabs', () => {
primaryTabs.forEach((t) => {
cy.contains(t).click();
// Like this
cy.reUseAnotherIt('swtich second tabs');
});
});
it('swtich second tabs', () => {
secondTabs.forEach((t) => {
cy.contains(t).click();
});
});
}); Is there any better approach? The main goal is to make "it" nestable. |
Beta Was this translation helpful? Give feedback.
Answered by
emilyrohrbough
Sep 8, 2022
Replies: 1 comment 1 reply
-
It's not possible to re-use the describe('nested tabs', ()=> {
;[
{ name: 'primary', tabs: primaryTabs},
{ name: 'second', tabs: secondTabs},
].forEach(({ name, tabs }) => {
it(`switches ${name} tabs`, () => {
tabs.forEach((t) => {
cy.contains(t).click();
})
})
})
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
iamyoki
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not possible to re-use the
it
however you could pull out the logic into a re-usable function that is shared between tests or you could dynamically create these cases if it helped clean things up for you.