avocado/packages/behavior/test/timing.js
2021-01-05 11:25:37 -06:00

40 lines
957 B
JavaScript

import {Latus} from '@latus/core';
import {expect} from 'chai';
import {
buildInvoke,
buildValue,
} from '../src/builders';
import Context from '../src/context';
import compile from '../src/compilers/compile';
let latus;
let context;
beforeEach(async () => {
latus = Latus.mock({
'@avocado/behavior': require('../src'),
});
await Promise.all(latus.invokeFlat('@latus/core/starting'));
context = new Context({}, latus);
});
describe('Timing', () => {
it('waits', async () => {
const DELAY = 30;
const tickingPromise = compile(buildInvoke(
['Timing', 'wait'],
[
buildValue(300),
],
), latus)(context);
tickingPromise.tick(200);
let start = Date.now();
await Promise.race([
new Promise((resolve) => setTimeout(resolve, DELAY)),
tickingPromise,
])
expect(Date.now() - start).to.be.at.least(DELAY * 0.9);
tickingPromise.tick(100);
return tickingPromise;
});
});