Node.js 如何重构MochaBDD测试?
我的解决方案不起作用Node.js 如何重构MochaBDD测试?,node.js,mocha.js,Node.js,Mocha.js,我的解决方案不起作用 const port = require('../app').port const superagent = require('superagent') const expect = require('expect') const server = require('http').createServer(app) const boot = () => { server.listen(app.get('port'), () => { console
const port = require('../app').port
const superagent = require('superagent')
const expect = require('expect')
const server = require('http').createServer(app)
const boot = () => {
server.listen(app.get('port'), () => {
console.info(`Express server listening on port ${app.get('port')}`)
})
}
当我尝试
mocha tests
Express.js server is listening on port 3000
ReferenceError: app is not defined
OP建议这样做
const server = http.createServer(app)
但在这种情况下,我得到了输出
ReferenceError: http is not defined
文件夹
-rw-rw-r-- 1 miki miki 503 апр 14 18:07 app.js
drwxrwxr-x 2 miki miki 4096 апр 14 17:43 db/
drwxrwxr-x 235 miki miki 12288 апр 14 18:43 node_modules/
-rw-rw-r-- 1 miki miki 413 апр 14 18:43 package.json
-rw-rw-r-- 1 miki miki 91189 апр 14 18:43 package-lock.json
drwxrwxr-x 2 miki miki 4096 апр 14 17:43 public/
drwxrwxr-x 2 miki miki 4096 апр 14 17:43 routes/
drwxrwxr-x 2 miki miki 4096 апр 14 18:16 test-example/
drwxrwxr-x 2 miki miki 4096 апр 14 18:30 tests/
drwxrwxr-x 2 miki miki 4096 апр 14 17:55 views/
如何解决此问题?您需要实际导入
应用程序
-模块才能使用它。像这样的方法应该会奏效:
const app = require('../app'); // adjust the path if necessary
const superagent = require('superagent')
const expect = require('expect')
const server = require('http').createServer(app)
const boot = () => {
server.listen(app.get('port'), () => {
console.info(`Express server listening on port ${app.get('port')}`)
})
}