-
Notifications
You must be signed in to change notification settings - Fork 0
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
29 changed files
with
1,739 additions
and
65 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,31 @@ | ||
import { isEnabled, setEnabled } from '../enabled'; | ||
|
||
describe('isEnabled()', () => { | ||
it('should be enabled by default', () => { | ||
expect(isEnabled()).toBe(true); | ||
}); | ||
|
||
describe('When set disabled', () => { | ||
beforeEach(() => { | ||
setEnabled(false); | ||
}); | ||
|
||
afterEach(() => { | ||
setEnabled(true); | ||
}); | ||
|
||
it('should return false', () => { | ||
expect(isEnabled()).toBe(false); | ||
}); | ||
|
||
describe('When set enabled', () => { | ||
beforeEach(() => { | ||
setEnabled(true); | ||
}); | ||
|
||
it('should return true', () => { | ||
expect(isEnabled()).toBe(true); | ||
}); | ||
}); | ||
}); | ||
}); |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,55 @@ | ||
import { isTypeChecked, isValidTarget } from '../utils'; | ||
|
||
import { INFO_KEY } from '../target/info'; | ||
|
||
import { TARGET_KEY } from '../target/proxy'; | ||
|
||
class MyClass {} | ||
|
||
describe('isValidTarget()', () => { | ||
it('should return true for object', () => { | ||
expect(isValidTarget({})).toBe(true); | ||
expect(isValidTarget([])).toBe(true); | ||
expect(isValidTarget(() => null)).toBe(true); | ||
expect(isValidTarget(new MyClass())).toBe(true); | ||
expect(isValidTarget(new Date())).toBe(true); | ||
}); | ||
|
||
it('should return false for primitive values', () => { | ||
expect(isValidTarget('123')).toBe(false); | ||
expect(isValidTarget(123)).toBe(false); | ||
expect(isValidTarget(false)).toBe(false); | ||
expect(isValidTarget(null)).toBe(false); | ||
expect(isValidTarget(Symbol('123'))).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isTypeChecked()', () => { | ||
it('should return false for not an object', () => { | ||
expect(isTypeChecked(null)).toBe(false); | ||
expect(isTypeChecked('123')).toBe(false); | ||
expect(isTypeChecked(123)).toBe(false); | ||
expect(isTypeChecked(true)).toBe(false); | ||
expect(isTypeChecked(Symbol('123'))).toBe(false); | ||
}); | ||
|
||
it('should return false for random objects', () => { | ||
expect(isTypeChecked({})).toBe(false); | ||
expect(isTypeChecked([])).toBe(false); | ||
expect(isTypeChecked(() => null)).toBe(false); | ||
expect(isTypeChecked(new Date())).toBe(false); | ||
expect(isTypeChecked(new MyClass())).toBe(false); | ||
}); | ||
|
||
it('should return false for objects with INFO_KEY', () => { | ||
expect(isTypeChecked({ [INFO_KEY]: {} })).toBe(false); | ||
expect(isTypeChecked(Object.assign([], { [INFO_KEY]: {} }))).toBe(false); | ||
expect(isTypeChecked(Object.assign(() => null, { [INFO_KEY]: {} }))).toBe(false); | ||
}); | ||
|
||
it('should return true for objects with TARGET_KEY', () => { | ||
expect(isTypeChecked({ [TARGET_KEY]: {} })).toBe(true); | ||
expect(isTypeChecked(Object.assign([], { [TARGET_KEY]: {} }))).toBe(true); | ||
expect(isTypeChecked(Object.assign(() => null, { [TARGET_KEY]: {} }))).toBe(true); | ||
}); | ||
}); |
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,25 @@ | ||
import { getDefaultTypeChecker, setDefaultTypeChecker } from '../index'; | ||
|
||
describe('getDefaultTypeChecker()', () => { | ||
let checker; | ||
|
||
beforeEach(() => { | ||
checker = { type: 'checker' }; | ||
}); | ||
|
||
describe('When accessing default', () => { | ||
it('should be null', () => { | ||
expect(getDefaultTypeChecker()).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('When specifying default', () => { | ||
beforeEach(() => { | ||
setDefaultTypeChecker(checker); | ||
}); | ||
|
||
it('should be checker instance', () => { | ||
expect(getDefaultTypeChecker()).toBe(checker); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.