Node.js 未捕获异常测试获取资源

Node.js 未捕获异常测试获取资源,node.js,express,testing,jestjs,Node.js,Express,Testing,Jestjs,我有一个小项目,我创建了一个简单的测试: 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 () => {

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

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测试时,我得到:

 No tests found in tests/users.test.js
 1 uncaught exception
npm测试
package.json中的定义:
“测试”:“ava测试/**”


你知道为什么我得到的是异常而不是“测试通过了”吗?

在该输出中也应该有堆栈跟踪,我得到如下结果:

❯ npm t

> alpha-node@0.0.0 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)
❯ 净现值
>阿尔法-node@0.0.0test/private/var/folders/2_/qczp184x76b2nl034sq5hvxw0000gn/T/tmp.PCqu6DgMB6/node-alpha
>ava试验/**
✖ 在tests/users.test.js中未找到任何测试
1未捕获异常
tests/users.test.js中的未捕获异常
/private/var/folders/2_/qczp184x76b2nl034sq5hvxw0000gn/T/tmp.PCqu6DgMB6/node alpha/node_modules/express/lib/router/index.js:635
TypeError:无法读取未定义的属性“apply”
node_modules/express/lib/router/index.js:635:15
下一步(node_modules/express/lib/router/index.js:210:14)
Function.handle(node_modules/express/lib/router/index.js:174:3)
路由器(node_modules/express/lib/router/index.js:47:12)
对象(tests/users.test.js:8:1)

异常正在阻止测试运行。

谢谢标记。我编辑了这个问题——我从一个使用jest而不是ava的项目中复制了这个测试。节点测试初学者在这里。目标是测试GET资源
用户
。我看到了异常,您知道使用
express
来避免此错误的正确方法是什么吗?