我正在尝试检查从http请求返回的响应代码,但是下面的assert语句始终在传递。最后的陈述 Expect(response.statusCode)应该失败并不确定出什么问题。这是我第一次使用mocha和chai框架进行测试。
const expect = require('chai').expect;
const mocha = require('mocha')
var request = require("request");
var should = require('chai').should();
const assert = require('assert');
var options = { method: 'POST',
url: 'https://technology.com.au/ing/api/v2/auth',
headers:
{ 'Content-Type': 'application/json',
'xapi-version': '1' },
body:
{ application: 'ERD',
username: 'GerSP',
password: '1234' },
json: true };
describe('Login Test' , function () {
it('should fail', function () {
request(options, function (error, response, body) {
if (error) throw new Error(error);
//console.log(body);
}).on('response', function(response) {
response.on('data', function(data) {
console.log('response .. ' + response.statusCode)
// Its suppose to fail
**expect(response.statusCode).to.equal(601);**
});
});
});
})