]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - example/iot-gateway/node_modules/aws-iot-device-sdk/node_modules/mqtt/node_modules/reinterval/tests/test.js
Updated to use the latest TI 15.4-Stack v2.1.0 from the SimpleLink CC13x0 SDK v1.30.
[apps/tidep0084.git] / example / iot-gateway / node_modules / aws-iot-device-sdk / node_modules / mqtt / node_modules / reinterval / tests / test.js
1 'use strict';
2 require('es6-shim');
4 var chai = require('chai');
5 var chaiAsPromised = require('chai-as-promised');
6 var reInterval = require('../index.js');
8 describe('reInterval', function() {
10   it('should work as an usual setInterval', function () {
11     return new Promise(function (resolve, reject) {
12       var startTime = new Date().getTime();
14       reInterval(function () {
15         if (Math.abs(new Date().getTime() - startTime - 1000) <= 10)
16           resolve();
17         else
18           reject(new Error('Took too much (or not enough) time'));
19       }, 1000);
20     });
21   });
23   it('should be able to clear an Interval', function () {
24     return new Promise(function (resolve, reject) {
25       var startTime = new Date().getTime();
27       var interval = reInterval(function () {
28           reject(new Error('Interval not cleared'));
29       }, 200);
31       setTimeout(interval.clear, 100);
33       setTimeout(resolve, 300);
34     });
35   });
37   it('should be able to reschedule an Interval', function () {
38     return new Promise(function (resolve, reject) {
39       var startTime = new Date().getTime();
41       var interval = reInterval(function () {
42         if (Math.abs(new Date().getTime() - startTime - 800) <= 10)
43           resolve();
44         else
45           reject(new Error('Took too much (or not enough) time'));
46       }, 500);
48       setTimeout(interval.reschedule, 300, [500])
49     });
50   });
52 });