1

所以我写了一个登录用户的测试:

describe('Login', () => {

beforeEach(async () => {
    await device.reloadReactNative()
  })

  it('Should grant access to a user with valid credentials', async () => {
    test code
  })
})

现在我正在编写一个新的规范来注销用户,所以我希望登录规范在注销规范中运行,而不是再次编写相同的测试代码。我想它看起来像:

describe('Log Out', () => {

beforeEach(async () => {
    await device.reloadReactNative()
    it ('Should grant access to a user with valid credentials')
  })

  it('A User Logs Out', async () => {
    test code
  })

在继续执行新步骤之前,如何让 Detox 运行第一次登录测试?

不幸的是,beforeEach it('应该授予具有有效凭据的用户访问权限')不起作用,所以我在语法中遗漏了一些东西。

4

2 回答 2

1

这与 Detox 无关,这个 describe/it API 与您正在使用的测试运行器有关。无论如何,使用函数:

describe('Login', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
    await grantAccessToUserWithValidCredentials();
  });

  it('A User Logs Out', async () => {
    // here the app is ready for you specific log out use case 
  });

  async function grantAccessToUserWithValidCredentials() {
    //grant it
  }
});
于 2018-03-14T19:18:26.267 回答
0

最佳实践是在测试中使用驱动程序。您可以查看这些幻灯片: http ://slides.com/shlomitoussiacohen/testing-react-components#/7

于 2018-03-21T14:40:21.300 回答