smarttime/test/test.ts

51 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

// tslint:disable-next-line:no-implicit-dependencies
import { expect, tap } from '@pushrocks/tapbundle';
2018-03-11 15:44:32 +00:00
import * as smarttime from '../ts/index';
2017-08-16 12:29:12 +00:00
// Test TimeStamp class
2018-03-11 15:44:32 +00:00
let testTimeStamp: smarttime.TimeStamp;
let testTimeStamp2: smarttime.TimeStamp;
tap.test('should create valid testTimeStamp instance', async tools => {
testTimeStamp = new smarttime.TimeStamp();
await tools.delayFor(2);
testTimeStamp2 = new smarttime.TimeStamp();
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp);
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp);
});
2017-08-16 12:29:12 +00:00
tap.test('should have valid linuxtime', async () => {
// tslint:disable-next-line:no-unused-expression
2018-03-11 15:44:32 +00:00
expect(testTimeStamp.isOlderThan(testTimeStamp2)).to.be.true;
2017-08-16 12:39:25 +00:00
// tslint:disable-next-line:no-unused-expression
expect(testTimeStamp.isYoungerThanOtherTimeStamp(testTimeStamp2)).to.be.false;
2018-03-11 15:44:32 +00:00
});
2017-08-15 17:28:23 +00:00
2018-03-11 15:44:32 +00:00
let testHrtMeasurement: smarttime.HrtMeasurement;
2017-08-16 12:29:12 +00:00
// Test HrtMeasurement
2018-03-11 15:44:32 +00:00
tap.test('should create valid HrtMeasurements', async tools => {
testHrtMeasurement = new smarttime.HrtMeasurement();
testHrtMeasurement.start();
await tools.delayFor(20);
testHrtMeasurement.stop();
expect(testHrtMeasurement.milliSeconds).to.be.greaterThan(19);
expect(testHrtMeasurement.milliSeconds).to.be.lessThan(25);
});
2017-08-16 12:29:12 +00:00
2017-08-16 14:24:56 +00:00
// check units
tap.test('should combine units', async () => {
const computedTime = smarttime.getMilliSecondsFromUnits({
2017-08-16 14:24:56 +00:00
years: 2,
// tslint:disable-next-line:object-literal-sort-keys
2017-08-16 14:24:56 +00:00
months: 2,
weeks: 2,
days: 2,
hours: 2,
minutes: 2
2018-03-11 15:44:32 +00:00
});
2018-03-11 23:13:17 +00:00
// tslint:disable-next-line:no-console
2018-03-11 15:44:32 +00:00
console.log(computedTime);
});
2017-08-16 12:29:12 +00:00
2018-03-11 15:44:32 +00:00
tap.start();