저는 단위 테스트, mocha 및 should.js에 익숙하지 않으며 약속을 반환하는 비동기 메서드에 대한 테스트를 작성하려고합니다. 여기 내 테스트 코드입니다 : 내가 수동으로 tideRetriever.get
방법을 테스트 할 때should.js는 모카 테스트 실패를 야기하지 않습니다.
var should = require("should"),
tideRetriever = require("../tide-retriever"),
moment = require("moment"),
timeFormat = "YYYY-MM-DD-HH:mm:ss",
from = moment("2013-03-06T00:00:00", timeFormat),
to = moment("2013-03-12T23:59:00", timeFormat),
expectedCount = 300;
describe("tide retriever", function() {
it("should retrieve and parse tide CSV data", function() {
tideRetriever.get(from, to).then(
function(entries) { // resolve
entries.should.be.instanceof(Array).and.have.lengthOf(expectedCount);
},
function(err) { // reject
should.fail("Promise rejected", err);
}
);
});
});
, 그것은 지속적으로 (예상대로) (27 개) 요소의 배열을 해결하지만, 시험에 관계없이 expectedCount
의 가치를 실패하지 않습니다. 다음은 간단한 수동 테스트입니다.
tideRetriever.get(from, to).then(
function(entries) {
console.log(entries, entries.length);
},
function(err) {
console.log("Promise rejected", err);
}
);
또한 필요한 경우 테스트중인 모듈의 소스를 게시 할 수도 있습니다.
나는 모카 또는 should.js에 대해 오해하고 있습니까? 어떤 도움이라도 대단히 감사하겠습니다.
기능의 매개 변수로 "done"을 추가하는 것을 잊어 버렸습니다. – Chaoste
@Chaoste thanks, fixed. –