【发布时间】:2020-06-25 02:18:47
【问题描述】:
从最近几天开始,我一直在使用 mocha、supertest 和 proxyquire。
我能够毫无问题地进行集成测试。但我有一些问题。
这是我项目中的一个测试套件。
const expect = require('chai').expect
const request = require('supertest')
const _ = require('lodash')
const sinon = require('sinon')
const faker = require('faker')
describe('ComboController /api/v1/combos', function () {
const app = require('../src/app')
it('should GET combo of given id: getComboById', async () => {
const response = await request(app)
.get(`/api/v1/combos/${faker.random.alphaNumeric(1)}`)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
const body = response.body
expect(body).to.have.keys('status', 'message', 'data')
expect(body.status).to.be.a('Boolean').true
expect(body.data).to.be.a('Object')
})
})
所以在这里我想知道。
摩卡在这里的作用是什么?
我知道 supertest 我可以发出 http 请求。
但是对于每个测试套件,我都传递了一个 express 应用程序的实例。
那么,supertest 对那个 express 应用程序做了什么?
每次发出请求时都会创建新服务器吗?
..如果是这样,是否可以为每个测试套件只创建一个快速服务器?
【问题讨论】:
标签: node.js express mocha.js supertest