-
Notifications
You must be signed in to change notification settings - Fork 27
/
call-nothrow.test.js
72 lines (59 loc) · 1.96 KB
/
call-nothrow.test.js
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
/* eslint-disable no-underscore-dangle, no-console */
import { runScriptlet, clearGlobalProps } from '../helpers';
const { test, module } = QUnit;
const name = 'call-nothrow';
const beforeEach = () => {
window.__debug = () => {
window.hit = 'FIRED';
};
};
const afterEach = () => {
clearGlobalProps('hit', '__debug');
};
module(name, { beforeEach, afterEach });
test('Checking if alias name works', (assert) => {
const adgParams = {
name,
engine: 'test',
verbose: true,
};
const uboParams = {
name: 'ubo-call-nothrow.js',
engine: 'test',
verbose: true,
};
const codeByAdgParams = window.scriptlets.invoke(adgParams);
const codeByUboParams = window.scriptlets.invoke(uboParams);
assert.strictEqual(codeByAdgParams, codeByUboParams, 'ubo name - ok');
});
test('call-nothrow - JSON.parse', (assert) => {
let testPassed;
runScriptlet(name, ['JSON.parse']);
// JSON.parse('foo') throws an error,
// so scriptlet should catch it and testPassed should be true
try {
JSON.parse('foo');
testPassed = true;
} catch (e) {
testPassed = false;
}
assert.strictEqual(testPassed, true, 'testPassed set to true');
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
});
test('call-nothrow - Object.defineProperty', (assert) => {
let testPassed;
const foo = {};
Object.defineProperty(foo, 'bar', { value: true });
runScriptlet(name, ['Object.defineProperty']);
// Redefining foo.bar should throw an error,
// so scriptlet should catch it and testPassed should be true
try {
Object.defineProperty(foo, 'bar', { value: false });
testPassed = true;
} catch (e) {
testPassed = false;
}
assert.strictEqual(testPassed, true, 'testPassed set to true');
assert.strictEqual(foo.bar, true, 'foo.bar set to true');
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
});