taskbuffer/test/test.6.taskonce.ts

29 lines
678 B
TypeScript
Raw Permalink Normal View History

2018-08-04 15:53:22 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2017-07-12 14:45:18 +00:00
2018-08-04 15:53:22 +00:00
import * as taskbuffer from '../ts/index';
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
});
expect(myTaskOnce).to.be.instanceof(taskbuffer.TaskOnce);
});
2017-07-12 14:45:18 +00:00
tap.test('myNumber should still be 0', async () => {
2018-08-04 15:53:22 +00:00
expect(myNumber).to.equal(0);
});
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();
expect(myNumber).to.equal(1);
});
2017-07-12 14:45:18 +00:00
2018-08-04 15:53:22 +00:00
tap.start();