0
如果我有一组URL来访问:执行多个摩卡测试
let tests = [
{ status: 200, mediaType: 'text/html', req: { method: 'GET', uri: 'http://stackoverflow.com/' } },
{ status: 200, mediaType: 'text/html', req: { method: 'GET', uri: 'http://stackoverflow.com999/' } },
{ status: 200, mediaType: 'text/html', req: { method: 'GET999', uri: 'http://stackoverflow.com/' } },
]
和一组测试对每个执行:
it('should have status ' + test.status,() => {
expect(test.response.statusCode).to.equal(test.status)
})
it('should have content type ' + test.mediaType,() => {
let s = test.response.headers['content-type']
let mediaType = s.indexOf(';') === -1 ? s : s.substr(0, s.indexOf(';'))
expect(mediaType).to.equal(test.mediaType)
})
it('should have a body',() => {
expect(test.body).to.not.equal('')
})
我怎样才能在每套测试中只执行一次昂贵的操作?另外,如果URL不加载,我不想运行测试。
为什么不直接使用'before'? – shawon191
这确实比较好。我用'之前'更新了答案。 TX! – ericP