因此,我对mocha完全不熟悉,并且我被要求编写集成测试,将表单数据发布到页面,获取身份验证密钥,然后对密钥运行测试.
我正确地获得了密钥,这可以通过我的日志声明来确认,但是当我运行mocha时,我的测试表示0传递.它甚至没有打印出'describe'和'it'语句的描述,暗示它们在promise中不起作用.有没有我可以这样工作,同时仍然让断言访问我的授权密钥?
require('should');
require('sails');
var Promise = require("promise");
var request = require('request');
describe('Domain Model', function(){
var options = { url:'link',
form:{
username: 'xxxxx@xxxxxx',
password: '0000'
},
timeout: 2000
};
//request auth key
var promise = new Promise(function(resolve,reject){
request.post(options, function(error, response, body){
//body contains the auth key, within a string of JSON
resolve(body);
});
});
//this is where I'm getting lost
promise.then(function(data,test){
var token = (JSON.parse(data))["access_token"];
console.log(token);
describe('Initialize',function(){
it('should be an string', function(){
(token).should.be.type('string');
});
});
});
});
Run Code Online (Sandbox Code Playgroud)