일부 게시물을 가져올 노드 모듈을 만들려고하지만 정의되지 않은 오류가 발생합니다.노드 모듈 반품 반환되지 않음
하는 index.js
var request = require('request');
function getPosts() {
var options = {
url: 'https://myapi.com/posts.json',
headers: {
'User-Agent': 'request'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
return JSON.parse(body);
}
}
request(options, callback);
}
exports.posts = getPosts;
테스트 /하는 index.js
var should = require('chai').should(),
myModule = require('../index');
describe('Posts call', function() {
it('should return posts', function() {
myModule.posts().should.equal(100);
});
});
나는 무엇을 놓치고? 오타 후 편집
'getPosts'는 아무 것도 반환하지 않습니다 – naomik