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