mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
tests: waitForPromise()
test improvements
* Avoid a false positive if a Promise that is expected to reject doesn't reject. * Use modern JavaScript language features: arrow functions, `const`/`let` instead of `var`. * Remove the tests that test Promise behavior. * Add new test that checks that it returns a Promise.
This commit is contained in:
parent
a3f062af96
commit
50e402193b
1 changed files with 18 additions and 37 deletions
|
@ -216,52 +216,33 @@ describe("the test helper", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('the waitForPromise method', function() {
|
describe('the waitForPromise method', function() {
|
||||||
|
it('returns a Promise', async function() {
|
||||||
|
expect(helper.waitForPromise(() => true)).to.be.a(Promise);
|
||||||
|
});
|
||||||
|
|
||||||
it('takes a timeout and waits long enough', async function() {
|
it('takes a timeout and waits long enough', async function() {
|
||||||
this.timeout(2000);
|
this.timeout(2000);
|
||||||
var startTime = Date.now();
|
const startTime = Date.now();
|
||||||
await helper.waitForPromise(function() {
|
let rejected;
|
||||||
return false;
|
await helper.waitForPromise(() => false, 1500)
|
||||||
}, 1500).catch(function() {
|
.catch(() => { rejected = true; });
|
||||||
var duration = Date.now() - startTime;
|
expect(rejected).to.be(true);
|
||||||
|
const duration = Date.now() - startTime;
|
||||||
expect(duration).to.be.greaterThan(1490);
|
expect(duration).to.be.greaterThan(1490);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('takes an interval and checks on every interval', async function() {
|
it('takes an interval and checks on every interval', async function() {
|
||||||
this.timeout(4000);
|
this.timeout(4000);
|
||||||
var checks = 0;
|
let checks = 0;
|
||||||
await helper.waitForPromise(function() {
|
let rejected;
|
||||||
checks++;
|
await helper.waitForPromise(() => { checks++; return false; }, 2000, 100)
|
||||||
return false;
|
.catch(() => { rejected = true; });
|
||||||
}, 2000, 100).catch(function() {
|
expect(rejected).to.be(true);
|
||||||
expect(checks).to.be.greaterThan(15);
|
expect(checks).to.be.greaterThan(15);
|
||||||
expect(checks).to.be.lessThan(21);
|
expect(checks).to.be.lessThan(21);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('returns a Promise', function() {
|
|
||||||
it('calls then after success', async function() {
|
|
||||||
let called = false;
|
|
||||||
await helper.waitForPromise(function() {
|
|
||||||
return true;
|
|
||||||
}).then(function() {
|
|
||||||
called = true;
|
|
||||||
});
|
|
||||||
expect(called).to.be(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls catch on failure', async function() {
|
|
||||||
let called = false;
|
|
||||||
await helper.waitForPromise(function() {
|
|
||||||
return false;
|
|
||||||
},0).catch(function() {
|
|
||||||
called = true;
|
|
||||||
});
|
|
||||||
expect(called).to.be(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("the selectLines method", function(){
|
describe("the selectLines method", function(){
|
||||||
// function to support tests, use a single way to represent whitespaces
|
// function to support tests, use a single way to represent whitespaces
|
||||||
var cleanText = function(text){
|
var cleanText = function(text){
|
||||||
|
|
Loading…
Reference in a new issue