Sto cercando di implementare un test di gelsomino su una semplice implementazione promessa (codice asincrono) con la funzione di fatto() e il mio test non riesce, anche se il codice in fase di sperimentazione opere perfettamente bene. Qualcuno può aiutarmi a capire cosa manca nel mio test?testare la funzionalità asincrona in Jasmine 2.0.0 con DONE()
var Test = (function() {
function Test(fn) {
this.tool = null;
fn(this.resolve.bind(this));
}
Test.prototype.then = function (cb) {
this.callback = cb;
};
Test.prototype.resolve = function (value) {
var me = this;
setTimeout(function() {
me.callback(value);
}, 5000);
};
return Test;
})();
describe("setTimeout", function() {
var test, newValue = false,
originalTimeout;
beforeEach(function (done) {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
test = new Test(function (cb) {
setTimeout(function() {
cb();
}, 5000);
});
test.then(function() {
newValue = true;
console.log(1, newValue);
done();
});
});
it("Should be true", function (done) {
expect(1).toBe(1);
expect(newValue).toBeTruthy();
});
afterEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
});
la stessa prova in jsfiddle: http://jsfiddle.net/ravitb/zsachqpg/
Inoltre, se * si * è necessario modificare l'intervallo di timeout su una base per test, è sufficiente passare l'intervallo personalizzato come terzo parametro a 'it()' (cioè dopo la funzione: 'it (desc , function (done) {...}, 10000); '.) – Kev
@Lior Si prega di aiutare questo: https://stackoverflow.com/questions/45311260/how-to-test-an-asynchronous-function-using- karma-gelsomino-in-ionic2 – Aditya