How to add custom message to Jest expect?

前端 未结 8 1204
鱼传尺愫
鱼传尺愫 2021-02-03 17:35

Image following test case:

it(\'valid emails checks\', () => {
  [\'abc@y.com\', \'a@b.nz\'/*, ...*/].map(mail => {
    expect(isValid(mail)).toBe(true);
          


        
8条回答
  •  梦谈多话
    2021-02-03 18:11

    You can use try-catch:

    try {
        expect(methodThatReturnsBoolean(inputValue)).toBeTruthy();
    }
    catch (e) {
        throw new Error(`Something went wrong with value ${JSON.stringify(inputValue)}`, e);
    }
    

提交回复
热议问题