捕获的错误显示在控制台中

时间:2017-10-29 13:50:35

标签: javascript mocha graphql apollo feathersjs

我的项目有2个测试:

"Foods can be fetched when authenticated"

"can not be fetched when not authenticated"

问题在于第二次测试。它期望一个由try / catch statemet拦截的错误。因此,我不希望在控制台中抛出错误,但确实如此。

直接使用promises同样存在问题。

我一直在挖掘Graphql和Feathers的源代码来解决这个问题,但没有成功。

我创建了一个最小可重复代码:https://github.com/jarnojellesma/feathers-graphql-test-error

it ('can not be fetched when not authenticated', async () => {
  const api = apolloClient();

  try {
    const res = await api.query({ query });
  } catch (e) {
    return expect(e.graphQLErrors[0].message).to.equal('No auth token');
  }

  fail('foods can be fetched when not authenticated');
});

控制台输出

Test
info: after: users - Method: create
info: after: users - Method: find
info: after: authentication - Method: create
info: after: foods - Method: remove
    foods
info: after: foods - Method: create
info: after: foods - Method: create
info: after: foods - Method: create
info: after: users - Method: get
info: after: users - Method: get
info: after: foods - Method: find
      ✓ can be fetched when authenticated (81ms)
info: error: foods - Method: find: No auth token
error:  NotAuthenticated: No auth token
    at NotAuthenticated (/home/$USER/Desktop/examples/node_modules/feathers-errors/lib/index.js:100:17)
    at /home/$USER/Desktop/examples/node_modules/feathers-authentication/lib/hooks/authenticate.js:102:31
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
NotAuthenticated: No auth token
    at NotAuthenticated (/home/$USER/Desktop/examples/node_modules/feathers-errors/lib/index.js:100:17)
    at /home/$USER/Desktop/examples/node_modules/feathers-authentication/lib/hooks/authenticate.js:102:31
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
      ✓ can not be fetched when not authenticated

  'foods' service
    ✓ registered the service


  3 passing (1s)

0 个答案:

没有答案