节点笑话测试中未捕获的异常

问题描述 投票:0回答:1

我有一个小项目here,我创建了一个简单的测试:

const request = require('supertest');
const bodyParse` = require('body-parser');
const express = require('express');
const app = express()
    .use(bodyParser.json());

require('../routes')(app);

test('users',async () => {
    await request(app)
        .get('/users')
        .expect(200);
});

执行npm test时得到:

 No tests found in tests/users.test.js
 1 uncaught exception

npm test中的[package.json定义:"test": "ava tests/**"

任何想法为什么我都会得到异常而不是“通过测试”?

node.js testing jest
1个回答
0
投票

在输出中也应该有一个堆栈跟踪,我明白了:

❯ npm t

> [email protected] test /private/var/folders/2_/qczp184x76b2nl034sq5hvxw0000gn/T/tmp.PCqu6DgMB6/node-alpha
> ava tests/**



  ✖ No tests found in tests/users.test.js

  1 uncaught exception

  Uncaught exception in tests/users.test.js

  /private/var/folders/2_/qczp184x76b2nl034sq5hvxw0000gn/T/tmp.PCqu6DgMB6/node-alpha/node_modules/express/lib/router/index.js:635

  TypeError: Cannot read property 'apply' of undefined

  node_modules/express/lib/router/index.js:635:15
  next (node_modules/express/lib/router/index.js:210:14)
  Function.handle (node_modules/express/lib/router/index.js:174:3)
  router (node_modules/express/lib/router/index.js:47:12)
  Object.<anonymous> (tests/users.test.js:8:1)

异常阻止测试运行。

© www.soinside.com 2019 - 2024. All rights reserved.