为什么Chai断言不会在ava运行时运行?

时间:2017-08-09 15:11:15

标签: try-catch chai assertion ava

我正处于测试Slack机器人手柄的红色阶段,因此我预计会出现错误。

我有以下代码:

  generateHandler({ fetch }) {
    return async function(bot, message) {
      let status;
      try {
        let response = await fetch(endpoint, {
          method: 'POST',
          body: {build_parameters: { ALLOW_OVERWRITE: "true" }}
        });
        status = response.ok;
      } catch (error) {
        status = false;
      }
      return status;
    }
  }

我写了以下测试:

import test from 'ava';
import { expect } from 'chai';
const { generateHandler } = require('../lib/handlers/redeploy_master.js');


test('triggers a new build on circleci', async (t) => {
  const fetch = async (endpoint, { method, body }) => {
    const expectedBody = { build_parameters: { ALLOW_OVERWRITE: "true" } };
    expect(method).to.be('POST');
    expect(body).to.deep.equal(JSON.stringify(expectedBody));
    return Promise.resolve({ok: true});
  };
  const handler = generateHandler({fetch});
  const bot = {reply: () => {}};

  return await handler(bot, undefined);
});

预期行为

如果我用原生expect()替换ava断言:

t.true(endpoint.startsWith('http'));
t.is(method, 'POST');
t.deepEqual(body, JSON.stringify(expectedBody));

它抛出了我期待的错误:

   10:     t.is(method, 'POST');
   11:     t.deepEqual(body, JSON.stringify(expectedBody));
   12:     expect(method).to.be('POST');

  Difference:

  - {
  -   build_parameters: Object { … },
  - }
  + '{"build_parameters":{"ALLOW_OVERWRITE":"true"}}'

实际行为

我收到以下错误:

Test finished without running any assertions

使用assert提供相同的行为

问题

假设chai条款中的try…catch断言被捕获,而来自ava的断言不是吗?

0 个答案:

没有答案