Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiuz committed May 20, 2018
1 parent e9e62a0 commit aa8aa05
Show file tree
Hide file tree
Showing 29 changed files with 1,739 additions and 65 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ Library that reports assignments of values or function arguments, return values
6. +Implement "createDeep()"
7. Cache child info for arguments
8. +Add ability to setup custom value validators for default type checker
9. Ignore accessing functions from prototype all the time
9. +Ignore accessing functions from prototype all the time
10. Add option to ignore any kind of properties available via prototype
11. Implement replaceProperty()
11. +Implement replaceProperty() -> property()
12. +Add possibility to make proxy config be part of target's info
13. Move primitive type checker into separate repo
13. +Move primitive type checker into separate repo
14. Add possibility to register ignored names which will be just skipped whatewer is placed in, probably could be added to ExtendedTypeChecker.
15. Add methods to convert info objects into primitives and back so they could be stored, would be good to have a system that permanently stores types info for consecutive runs.
2 changes: 1 addition & 1 deletion dist/type-checkers.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/type-checkers.min.js.map

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions source/__tests__/enabled.js
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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@ import create from '../proxy/create';
import { isTypeChecked } from '../utils';
import { setDefaultTypeChecker } from '../checkers';

describe('When merging objects', () => {
const mockChecker = () => ({
init: jest.fn(() => ({ type: 'type-checker-config' })),
getProperty: jest.fn(),
setProperty: jest.fn(),
arguments: jest.fn(),
returnValue: jest.fn(),
mergeConfigs: jest.fn((config1, config2, names) => ({
config1,
config2,
names,
})),
});

describe('Object.assign()', () => {});

describe('merge()', () => {
let checker;
let target1;
let target2;

beforeEach(() => {
checker = {
init: jest.fn(() => ({ type: 'type-checker-config' })),
getProperty: jest.fn(),
setProperty: jest.fn(),
arguments: jest.fn(),
returnValue: jest.fn(),
};

checker = mockChecker();
setDefaultTypeChecker(checker);

target1 = create({
Expand All @@ -33,8 +41,6 @@ describe('When merging objects', () => {
expect(isTypeChecked(target1)).toBe(true);
expect(isTypeChecked(target2)).toBe(true);
});

describe('Object.assign()', () => {});

describe('merge()', () => {});
});

describe('properties()', () => {});
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions source/__tests__/utils.js
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);
});
});
25 changes: 25 additions & 0 deletions source/checkers/__tests__/index.js
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);
});
});
});
Loading

0 comments on commit aa8aa05

Please sign in to comment.