-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdsLib.test.js
More file actions
72 lines (64 loc) · 2.21 KB
/
hdsLib.test.js
File metadata and controls
72 lines (64 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { assert } from './test-utils/deps-node.js';
/**
* Tests related to HDSLib.index.js & utils
*/
import HDSLib from '../ts/index.ts';
import { waitUntilFalse } from '../ts/utils.ts';
import { resetModel } from '../ts/HDSModel/HDSModelInitAndSingleton.ts';
describe('[HDLX] HDSLib.index', () => {
before(async () => {
await HDSLib.initHDSModel();
resetModel();
});
it('[HDME] HDSLib.getHDSModel() throws error if not initialized', () => {
try {
HDSLib.getHDSModel().modelData;
throw new Error('Should throw an error');
} catch (e) {
assert.equal(e.message, 'Model not loaded call `HDSLib.initHDSModel()` or `await model.load()` first.');
}
try {
HDSLib.getHDSModel().streams;
throw new Error('Should throw an error');
} catch (e) {
assert.equal(e.message, 'Model not loaded call `HDSLib.initHDSModel()` or `await model.load()` first.');
}
});
it('[HDMF] HDSLib.initHDSModel()', async () => {
const model0 = await HDSLib.initHDSModel();
const model1 = await HDSLib.initHDSModel();
assert.equal(model0, model1, 'HDSLib.initHDSModel() should used cached model');
const model2 = HDSLib.getHDSModel();
assert.equal(model0, model2, 'HDSLib.getHDSModel() should used cached model');
// -- refresh model
});
describe('[HDUX] Utils', () => {
it('[HDUW] utils.waitUntilFalse', async function () {
this.timeout('1000');
let toBeSetToFalse = true;
setTimeout(() => { toBeSetToFalse = false; }, 500);
let count = 0;
await waitUntilFalse(() => {
count++;
return toBeSetToFalse;
}, 700);
assert.ok(count > 2, 'should do at least 2 loops');
});
it('[HDUW] utils.waitUntilFalse throw timout on error', async function () {
this.timeout('1000');
let toBeSetToFalse = true;
setTimeout(() => { toBeSetToFalse = false; }, 600);
let count = 0;
try {
await waitUntilFalse(() => {
count++;
return toBeSetToFalse;
}, 400);
throw new Error('Should throw errors');
} catch (e) {
assert.equal(e.message, 'Timeout after 400ms');
}
assert.ok(count > 2, 'should do at least 2 loops');
});
});
});