摩卡跳过测试
Mocha skipping over test
初学者(Node、JS)试图理解为什么 Mocha 会跳过我的测试。我意识到我使用的请求/超级测试库不是最理想的,但我只是想了解为什么当它在调试中遇到 'it' 时,它只是跳到 'describe' 块的右括号而没有运行 内的代码:
const request = require('supertest')('https://my-app123.com');
const createJWT = require('../../lib/createApp/createJWT');
const app = require('./app');
let jwt;
describe('App creation', () => {
it('should create new app', function(done) {
jwt = createJWT();
request
.post('/v1/home')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${jwt}`)
.send({
name: 'Test',
organisation: 'Test Inc.',
objectionProcessingDefault: 'auto-uphold',
users: [{
email: 'me@example.co.uk',
firstName: 'Dave',
lastName: 'Smith',
roles: ['ADMIN', 'STANDARD'],
}, ],
})
.expect(200, done);
});
});
感谢您对理解的任何帮助。
尝试让Nodejs先评估promise再比较。例如,它应该是
const api = request('https://123-api.myapplication.io', {
json: true
}, (err, res, body) => {
if (err) {
return console.log(err);
}
console.log(body.url);
console.log(body.explanation);
});
describe('POST /v1/creation', () => {
it('should return a 200', async() => {
const app = api();
let jwt = createJWT();
await (supertest(app)
.post('/v2/create')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${jwt}`)
.send({
name: 'Test',
organisation: 'Test Inc.',
objectionProcessingDefault: 'auto-uphold',
users: [{
email: 'me@example.co.uk',
firstName: 'Bob',
lastName: 'Smith',
roles: ['ADMIN', 'AGENT'],
}, ],
}))
.expect(200);
});
});
此外,通过查看您的代码,您可能需要在发出 post 请求之前设置 headers。
初学者(Node、JS)试图理解为什么 Mocha 会跳过我的测试。我意识到我使用的请求/超级测试库不是最理想的,但我只是想了解为什么当它在调试中遇到 'it' 时,它只是跳到 'describe' 块的右括号而没有运行 内的代码:
const request = require('supertest')('https://my-app123.com');
const createJWT = require('../../lib/createApp/createJWT');
const app = require('./app');
let jwt;
describe('App creation', () => {
it('should create new app', function(done) {
jwt = createJWT();
request
.post('/v1/home')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${jwt}`)
.send({
name: 'Test',
organisation: 'Test Inc.',
objectionProcessingDefault: 'auto-uphold',
users: [{
email: 'me@example.co.uk',
firstName: 'Dave',
lastName: 'Smith',
roles: ['ADMIN', 'STANDARD'],
}, ],
})
.expect(200, done);
});
});
感谢您对理解的任何帮助。
尝试让Nodejs先评估promise再比较。例如,它应该是
const api = request('https://123-api.myapplication.io', {
json: true
}, (err, res, body) => {
if (err) {
return console.log(err);
}
console.log(body.url);
console.log(body.explanation);
});
describe('POST /v1/creation', () => {
it('should return a 200', async() => {
const app = api();
let jwt = createJWT();
await (supertest(app)
.post('/v2/create')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${jwt}`)
.send({
name: 'Test',
organisation: 'Test Inc.',
objectionProcessingDefault: 'auto-uphold',
users: [{
email: 'me@example.co.uk',
firstName: 'Bob',
lastName: 'Smith',
roles: ['ADMIN', 'AGENT'],
}, ],
}))
.expect(200);
});
});
此外,通过查看您的代码,您可能需要在发出 post 请求之前设置 headers。