-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
233 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const ALS = require('../../dist/als/als').default; | ||
|
||
describe('ALS enable and disable tests', () => { | ||
test('Nesting of disable and exit should work as intended', () => { | ||
const store = new ALS(); | ||
store.run({}, () => { | ||
store.set('foo', 'bar'); | ||
process.nextTick(() => { | ||
expect(store.get('foo')).toEqual('bar'); | ||
process.nextTick(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
|
||
store.disable(); | ||
expect(store.getStore()).toBeUndefined(); | ||
|
||
// Calls to exit() should not mess with enabled status | ||
store.exit(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
expect(store.getStore()).toBeUndefined(); | ||
|
||
process.nextTick(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
store.run({ bar: 'foo' }, () => { | ||
expect(store.get('bar')).toEqual('foo'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
test('Exit should work as intended', () => { | ||
const store = new ALS(); | ||
store.run({}, () => { | ||
store.set('foo', 'bar'); | ||
store.exit(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
expect(store.get('foo')).toEqual('bar'); | ||
}); | ||
}); | ||
|
||
test('Exit should able to run when not inside run', () => { | ||
const store = new ALS(); | ||
const spyFn = jest.fn(); | ||
store.exit(() => { | ||
spyFn(); | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
expect(spyFn).toBeCalledTimes(1); | ||
}); | ||
|
||
test('Disable should work as intended', () => { | ||
const store = new ALS(); | ||
store.run({}, () => { | ||
store.set('foo', 'bar'); | ||
store.disable(); | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
store.disable(); // Wont trigger any error | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const CLS = require('../../dist/cls/cls').default; | ||
|
||
describe('CLS enable and disable tests', () => { | ||
test('Nesting of disable and exit should work as intended', () => { | ||
const store = new CLS(); | ||
store.run({}, () => { | ||
store.set('foo', 'bar'); | ||
process.nextTick(() => { | ||
expect(store.get('foo')).toEqual('bar'); | ||
process.nextTick(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
|
||
store.disable(); | ||
expect(store.getStore()).toBeUndefined(); | ||
|
||
// Calls to exit() should not mess with enabled status | ||
store.exit(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
expect(store.getStore()).toBeUndefined(); | ||
|
||
process.nextTick(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
store.run({ bar: 'foo' }, () => { | ||
expect(store.get('bar')).toEqual('foo'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
test('Exit should work as intended', () => { | ||
const CLS = require('../../dist/cls/cls').default; | ||
const store = new CLS(); | ||
store.run({}, () => { | ||
store.set('foo', 'bar'); | ||
store.exit(() => { | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
expect(store.get('foo')).toEqual('bar'); | ||
}); | ||
}); | ||
|
||
test('Exit should able to run when not inside run', () => { | ||
const store = new CLS(); | ||
const spyFn = jest.fn(); | ||
store.exit(() => { | ||
spyFn(); | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
expect(spyFn).toBeCalledTimes(1); | ||
}); | ||
|
||
test('Disable should work as intended', () => { | ||
const store = new CLS(); | ||
store.run({}, () => { | ||
store.set('foo', 'bar'); | ||
store.disable(); | ||
expect(store.getStore()).toBeUndefined(); | ||
}); | ||
store.disable(); // Wont trigger any error | ||
}); | ||
}); |