@tdb/util
Version:
Shared helpers and utilities.
58 lines (57 loc) • 2.3 kB
JavaScript
;
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var chai_1 = require("chai");
var libs_1 = require("../../libs");
var _1 = require(".");
describe('delay', function () {
it('delays then executes', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var startedAt, count;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
startedAt = libs_1.moment();
count = 0;
chai_1.expect(libs_1.moment().diff(startedAt)).to.be.lessThan(8);
return [4, _1.delay(10, function () { return (count += 1); })];
case 1:
_a.sent();
chai_1.expect(libs_1.moment().diff(startedAt)).to.be.greaterThan(8);
return [2];
}
});
}); });
it('does not fail when no callback is specified', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var startedAt;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
startedAt = libs_1.moment();
chai_1.expect(libs_1.moment().diff(startedAt)).to.be.lessThan(8);
return [4, _1.delay(10)];
case 1:
_a.sent();
chai_1.expect(libs_1.moment().diff(startedAt)).to.be.greaterThan(8);
return [2];
}
});
}); });
});
describe('wait', function () {
it('pauses for given time', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var startedAt;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
startedAt = libs_1.moment();
chai_1.expect(libs_1.moment().diff(startedAt)).to.be.lessThan(10);
return [4, _1.wait(15)];
case 1:
_a.sent();
chai_1.expect(libs_1.moment().diff(startedAt)).to.be.greaterThan(10);
return [2];
}
});
}); });
});