-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
executable file
·39 lines (33 loc) · 1.1 KB
/
index.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
const cls = require('./index')
const chai = require('chai');
const { expect } = chai;
describe('CLS', function () {
it('will maintain a value', async function () {
cls.something = 1
await new Promise(resolve => setTimeout(resolve, 100))
expect(cls.something).to.eq(1)
await (async () => {
await new Promise(resolve => setTimeout(resolve, 10))
expect(cls.something).to.eq(1)
})()
});
it('will lose values set in a sub function', async function () {
cls.something = 1
await new Promise(resolve => setTimeout(resolve, 100))
expect(cls.something).to.eq(1)
await (async () => {
cls.something = 2
})()
expect(cls.something).to.eq(1)
})
it("will keep the value if hold context was set", async function () {
cls.$init()
cls.something = 1
await new Promise(resolve => setTimeout(resolve, 100))
expect(cls.something).to.eq(1)
await (async () => {
cls.something = 2
})()
expect(cls.something).to.eq(2)
})
})