2023-07-26 12:16:33 +00:00
|
|
|
import { expect, tap } from '@push.rocks/tapbundle';
|
2017-07-12 14:45:18 +00:00
|
|
|
|
2022-03-25 11:14:49 +00:00
|
|
|
import * as taskbuffer from '../ts/index.js';
|
2017-07-12 14:45:18 +00:00
|
|
|
|
2018-08-04 15:53:22 +00:00
|
|
|
let myNumber = 0;
|
|
|
|
let myTaskOnce: taskbuffer.TaskOnce;
|
2017-07-12 14:45:18 +00:00
|
|
|
|
|
|
|
tap.test('should create a valid instance of TaskOnce', async () => {
|
|
|
|
myTaskOnce = new taskbuffer.TaskOnce({
|
|
|
|
taskFunction: async () => {
|
2018-08-04 15:53:22 +00:00
|
|
|
myNumber++;
|
2020-07-12 00:48:51 +00:00
|
|
|
},
|
2018-08-04 15:53:22 +00:00
|
|
|
});
|
2022-03-25 11:14:49 +00:00
|
|
|
expect(myTaskOnce).toBeInstanceOf(taskbuffer.TaskOnce);
|
2018-08-04 15:53:22 +00:00
|
|
|
});
|
2017-07-12 14:45:18 +00:00
|
|
|
|
|
|
|
tap.test('myNumber should still be 0', async () => {
|
2022-03-25 11:14:49 +00:00
|
|
|
expect(myNumber).toEqual(0);
|
2018-08-04 15:53:22 +00:00
|
|
|
});
|
2017-07-12 14:45:18 +00:00
|
|
|
|
|
|
|
tap.test('myTaskOnce should trigger once', async () => {
|
2018-08-04 15:53:22 +00:00
|
|
|
await myTaskOnce.trigger();
|
|
|
|
await myTaskOnce.trigger();
|
|
|
|
await myTaskOnce.trigger();
|
2022-03-25 11:14:49 +00:00
|
|
|
expect(myNumber).toEqual(1);
|
2018-08-04 15:53:22 +00:00
|
|
|
});
|
2017-07-12 14:45:18 +00:00
|
|
|
|
2018-08-04 15:53:22 +00:00
|
|
|
tap.start();
|