-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-als-defaultvalue-original.js
More file actions
37 lines (26 loc) · 1.01 KB
/
test-als-defaultvalue-original.js
File metadata and controls
37 lines (26 loc) · 1.01 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
// Flags: --no-async-context-frame
'use strict';
require('../common');
const {
AsyncLocalStorage,
} = require('async_hooks');
const assert = require('assert');
// ============================================================================
// The defaultValue option
const als1 = new AsyncLocalStorage();
assert.strictEqual(als1.getStore(), undefined);
const als2 = new AsyncLocalStorage({ defaultValue: 'default' });
assert.strictEqual(als2.getStore(), 'default');
const als3 = new AsyncLocalStorage({ defaultValue: 42 });
assert.strictEqual(als3.getStore(), 42);
const als4 = new AsyncLocalStorage({ defaultValue: null });
assert.strictEqual(als4.getStore(), null);
assert.throws(() => new AsyncLocalStorage(null), {
code: 'ERR_INVALID_ARG_TYPE',
});
// ============================================================================
// The name option
const als5 = new AsyncLocalStorage({ name: 'test' });
assert.strictEqual(als5.name, 'test');
const als6 = new AsyncLocalStorage();
assert.strictEqual(als6.name, '');