代码之家  ›  专栏  ›  技术社区  ›  invisal

将玩笑期待与排毒期待混为一谈

  •  1
  • invisal  · 技术社区  · 8 年前

    如何将玩笑预期与排毒预期结合起来?以下是我试图做的。看来 expect 预料

    await mockServer.mockAnyResponse({
        httpRequest: {
          method: 'POST', 
          path: '/api/register',
        },
        httpResponse: {
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            token: 'xxx',
          }),
        }
    });
    
    await element(by.id('name')).typeText('Robert');
    await element(by.id('password')).typeText('123456');
    await element(by.id('register')).tap();
    
    // Check if endpoint has been called
    let result = await mockServer.checkIfRegisterEndPointHasBeenCalled();
    expect(result).toBe(true); // <-- how to do something like this?
    
    2 回复  |  直到 8 年前
        1
  •  5
  •   noomorph    8 年前

    这分两个步骤完成:

    1. 当你使用 detox.init() ,传递一个假消息 initGlobals 参数,例如: detox.init({ initGlobals: false }) expect 开玩笑。
    2. 通过 const { device, expect } = require('detox');
        2
  •  1
  •   tom    8 年前

    另一个选择是忽视排毒过度的事实 expect 预料

    const jestExpect = require('expect');

        3
  •  1
  •   MikeL    7 年前

    不确定这对于一个更有经验的“测试人员”来说是否是显而易见的,但是另外两个答案只是部分正确,并且遗漏了一些我有点麻烦的东西:youget undefined 当您尝试访问或 require expect 在全球范围内,您必须在测试中这样做。


    在 init.js

    before(async () => {
      await detox.init(config, {initGlobals: false});
    });
    

    it (有 const )或者 before (有 let jestExpect describe ):

    jestExpect = require('expect');
    
    推荐文章