Jestjs Jest:编写需要先声明某些步骤的测试的正确方法是什么?

Jestjs Jest:编写需要先声明某些步骤的测试的正确方法是什么?,jestjs,Jestjs,我已经开始开玩笑地编写一些UI测试,现在,我需要测试一个模态。只有单击按钮后,模式才会打开。 我的代码如下。我想知道是否可以在每次测试之前将带有断言的getButton和getModal拉入另一个要运行的函数中。我想在每次见面之前就把它放进去,但我不确定这是否是最好的做法。欢迎任何建议 it('should open Modal when click on button', async () => { const button = getButton(); expect(b

我已经开始开玩笑地编写一些UI测试,现在,我需要测试一个模态。只有单击按钮后,模式才会打开。 我的代码如下。我想知道是否可以在每次测试之前将带有断言的
getButton
getModal
拉入另一个要运行的函数中。我想在每次见面之前就把它放进去,但我不确定这是否是最好的做法。欢迎任何建议

it('should open Modal when click on button', async () => {
    const button = getButton();
    expect(button.isDisplayed()).to.be.true;

    const modal = getModal();
    expect(modal.isDisplayed()).to.be.true;
});

it('should contain text and close icon', async () => {

    const button = getButton();
    expect(button.isDisplayed()).to.be.true;

    const modal = getModal();
    expect(modal.isDisplayed()).to.be.true;

    /* * some other code....*/

});