Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/common/assert.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ok, assert as commonAssert } from '../../common/assert.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
9
import { CancellationError, ReadonlyError } from '../../common/errors.js';
10
11
suite('Assert', () => {
12
test('ok', () => {
13
assert.throws(function () {
14
ok(false);
15
});
16
17
assert.throws(function () {
18
ok(null);
19
});
20
21
assert.throws(function () {
22
ok();
23
});
24
25
assert.throws(function () {
26
ok(null, 'Foo Bar');
27
}, function (e: Error) {
28
return e.message.indexOf('Foo Bar') >= 0;
29
});
30
31
ok(true);
32
ok('foo');
33
ok({});
34
ok(5);
35
});
36
37
suite('throws a provided error object', () => {
38
test('generic error', () => {
39
const originalError = new Error('Oh no!');
40
41
try {
42
commonAssert(
43
false,
44
originalError,
45
);
46
} catch (thrownError) {
47
assert.strictEqual(
48
thrownError,
49
originalError,
50
'Must throw the provided error instance.',
51
);
52
53
assert.strictEqual(
54
thrownError.message,
55
'Oh no!',
56
'Must throw the provided error instance.',
57
);
58
}
59
});
60
61
test('cancellation error', () => {
62
const originalError = new CancellationError();
63
64
try {
65
commonAssert(
66
false,
67
originalError,
68
);
69
} catch (thrownError) {
70
assert.strictEqual(
71
thrownError,
72
originalError,
73
'Must throw the provided error instance.',
74
);
75
}
76
});
77
78
test('readonly error', () => {
79
const originalError = new ReadonlyError('World');
80
81
try {
82
commonAssert(
83
false,
84
originalError,
85
);
86
} catch (thrownError) {
87
assert.strictEqual(
88
thrownError,
89
originalError,
90
'Must throw the provided error instance.',
91
);
92
93
assert.strictEqual(
94
thrownError.message,
95
'World is read-only and cannot be changed',
96
'Must throw the provided error instance.',
97
);
98
}
99
});
100
});
101
102
ensureNoDisposablesAreLeakedInTestSuite();
103
});
104
105