Skip to content

Commit

Permalink
fix test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
PhakornKiong committed Apr 1, 2021
1 parent 06da78e commit 0a0fa70
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
35 changes: 33 additions & 2 deletions tests/als/als.enable-disable.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const ALS = require('../../dist/als/als').default;
const store = new ALS();

describe('ALS enable and disable tests', () => {
test('Disable should work as intended', () => {
test('Nesting of disable and exit should work as intended', () => {
const store = new ALS();
store.run({}, () => {
store.set('foo', 'bar');
process.nextTick(() => {
Expand All @@ -29,4 +29,35 @@ describe('ALS enable and disable tests', () => {
});
});
});

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
});
});
36 changes: 34 additions & 2 deletions tests/cls/cls.enable-disable.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const CLS = require('../../dist/cls/cls').default;
const store = new CLS();

describe('CLS enable and disable tests', () => {
test('Disable should work as intended', () => {
test('Nesting of disable and exit should work as intended', () => {
const store = new CLS();
store.run({}, () => {
store.set('foo', 'bar');
process.nextTick(() => {
Expand All @@ -29,4 +29,36 @@ describe('CLS enable and disable tests', () => {
});
});
});

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
});
});

0 comments on commit 0a0fa70

Please sign in to comment.