我有一个Jasmine测试,里面有一些HTTP请求。我使用Axios进行基于承诺的HTTP访问,但出于某种原因我得到axios is not defined
。我已经开始npm install axios --save
var request = require('axios');
var constants = require('../../lib/constants.js');
describe('Signing into the application', function () {
it('returns 200 OK', function () {
axios.get(constants.Endpoint)
.then(function (response) {
console.log(JSON.stringify(response));
})
.catch(function (error) {
console.log(JSON.stringify(error));
});
});
});
这是输出:
Failures:
1) Signing into the application returns 200 OK
Message:
ReferenceError: axios is not defined
Stacktrace:
ReferenceError: axios is not defined
at jasmine.Spec.<anonymous> (C:\Users\la\Documents\tests\spec\integration\sign-in\sign-in-spec.js:6:9)
以下是package.json
:
{
"name": "actual-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jasmine-node spec"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.16.2",
"jasmine-node": "^1.14.5"
}
}
这里发生了什么?
答案 0 :(得分:2)
您已定义:
var request = require('axios');
试图打电话:
axios.get ...
将其更改为:
var axios = require('axios');