jasmine 1.3을 사용하는 jasmine-node 1.14.5를 사용 중이며 runs/waitFor
이 약속과 함께 올바르게 작동하도록하는 데 문제가 있습니다.Jasmine 1.3에서 실행/대기를 완료 한 후 약속 완료
특정 테스트에서는 특정 조건이 발생하기를 기다리는 runs/waitFor
을 원합니다. 발생하면 다시 돌아 오는 약속을 이행하십시오. 그러나 function(success, fail)
매개 변수에 전달하는 약속을 구성하려고 시도하면 runs/waitFor
안의 코드는 호출되지 않습니다. 그러나 약속이 직접 해결되면 작동합니다. 전 옵션이 효과가 없다는 아이디어는 있습니까?
it("should support async execution of test preparation and expectations", function(done) {
var p = Promise.resolve("boo")
.then(function() {
var p2 = Promise.resolve("whatever");
runs(function() {
flag = false;
value = 0;
intId = setInterval(function() {
console.log(value);
if (++value == 3) { clearInterval(intId); flag = true; }
}, 500);
});
waitsFor(function() {
return flag;
}, "The Value should be incremented", 5000);
runs(function() {
expect(value).toEqual(3);
});
return p2;
});
p.then(function() {
done();
}).catch(function(err) {
done(err);
});
});
그러나 다른 한편으로는,이 때문에 비록 runs/waitsFor
작동하지 않습니다
it("should support async execution of test preparation and expectations", function(done) {
var p = Promise.resolve("boo")
.then(function() {
return new Promise(function (fulfil, reject) {
runs(function() {
flag = false;
value = 0;
intId = setInterval(function() {
console.log(value);
if (++value == 3) {
clearInterval(intId);
flag = true;
}
}, 500);
});
waitsFor(function() {
return flag;
}, "The Value should be incremented", 5000);
runs(function() {
expect(value).toEqual(3);
fulfil();
});
});
});
p.then(function() {
done();
}).catch(function(err) {
done(err);
});
});
나는 또한 다음과 같은 시도를했으나 작동하지 않는다. 앞의 예제와 같은 방식으로 작동한다.
it("should support async execution of test preparation and expectations", function(done) {
var p = Promise.resolve("boo")
.then(function() {
var outerFulfil;
var outerReject;
var p2 = new Promise(function(fulfil, reject) {
outerFulfil = fulfil;
outerReject = reject;
});
runs(function() {
flag = false;
value = 0;
intId = setInterval(function() {
console.log(value);
if (++value == 3) { clearInterval(intId); flag = true; }
}, 500);
});
waitsFor(function() {
return flag;
}, "The Value should be incremented", 5000);
runs(function() {
expect(value).toEqual(3);
outerFulfil();
});
return p2;
});
p.then(function() {
done();
}).catch(function(err) {
done(err);
});
});
어떤 아이디어로 해결할 수 있습니까? 첫 번째 예제가 작동하지만, 내가 원하는 방식으로 작동하지 않습니다. 왜냐하면 waitsFor
이후의 주장이 수행 된 후에 만 약속이 이루어 지길 원하기 때문입니다.