Skip to content

Updating tests on validators using assert.isTrue() to verify correct cases #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions packages/metal-state/test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import validators from '../src/validators';

describe('validators', function() {
it('should validate an array', function() {
assert.ok(validators.array([], null, this));
assert.isTrue(validators.array([], null, this));

assert.ok(validators.array('string', null, this) instanceof Error);
});

it('should validate a boolean', function() {
assert.ok(validators.bool(true));
assert.isTrue(validators.bool(true));

assert.ok(validators.bool('true') instanceof Error);
});
Expand All @@ -21,44 +21,44 @@ describe('validators', function() {
return;
};

assert.ok(validators.func(testFn));
assert.isTrue(validators.func(testFn));

assert.ok(validators.func('testFn') instanceof Error);
});

it('should validate a number', function() {
assert.ok(validators.number(1));
assert.isTrue(validators.number(1));

assert.ok(validators.number('1') instanceof Error);
});

it('should validate a object', function() {
const obj = {};

assert.ok(validators.object(obj));
assert.isTrue(validators.object(obj));

assert.ok(validators.object('obj') instanceof Error);
});

it('should validate a string', function() {
assert.ok(validators.string('testString'));
assert.isTrue(validators.string('testString'));

assert.ok(validators.string(false) instanceof Error);
});

it('should validate any type', function() {
const validator = validators.any();
assert.ok(validator('testString'));
assert.ok(validator(false));
assert.ok(validator({}));
assert.ok(validator(1));
assert.ok(validator(function() {}));
assert.isTrue(validator('testString'));
assert.isTrue(validator(false));
assert.isTrue(validator({}));
assert.isTrue(validator(1));
assert.isTrue(validator(function() {}));
});

it('should validate an array of a single type', function() {
const arrayOfNumbers = validators.arrayOf(validators.number);

assert.ok(arrayOfNumbers([1, 2, 3, 4]));
assert.isTrue(arrayOfNumbers([1, 2, 3, 4]));

assert.ok(arrayOfNumbers([1, 2, 3, '4']) instanceof Error);

Expand All @@ -73,20 +73,20 @@ describe('validators', function() {

const instanceOfFn = validators.instanceOf(TestClass);

assert.ok(instanceOfFn(new TestClass()));
assert.isTrue(instanceOfFn(new TestClass()));

assert.ok(instanceOfFn(new TestClass2()) instanceof Error);
});

it('should validate a single type or null', function() {
assert.ok(validators.number(1));
assert.ok(validators.number(null));
assert.ok(validators.number(undefined));
assert.isTrue(validators.number(1));
assert.isTrue(validators.number(null));
assert.isTrue(validators.number(undefined));
assert.ok(validators.number('1') instanceof Error);

assert.ok(validators.object({}));
assert.ok(validators.object(null));
assert.ok(validators.object(undefined));
assert.isTrue(validators.object({}));
assert.isTrue(validators.object(null));
assert.isTrue(validators.object(undefined));
assert.ok(validators.object(1) instanceof Error);
});

Expand All @@ -98,8 +98,8 @@ describe('validators', function() {
]
);

assert.ok(validator('one'));
assert.ok(validator(1));
assert.isTrue(validator('one'));
assert.isTrue(validator(1));

assert.ok(validator('1') instanceof Error);
});
Expand All @@ -117,9 +117,9 @@ describe('validators', function() {
]
);

assert.ok(oneOfType('test'));
assert.isTrue(oneOfType('test'));

assert.ok(oneOfType(1));
assert.isTrue(oneOfType(1));

assert.ok(oneOfType({}) instanceof Error);
});
Expand All @@ -137,7 +137,7 @@ describe('validators', function() {
it('should validate an object with certain types of values', function() {
const objectOf = validators.objectOf(validators.number);

assert.ok(objectOf({
assert.isTrue(objectOf({
a: 1,
b: 2
}));
Expand All @@ -154,7 +154,7 @@ describe('validators', function() {
b: validators.number
});

assert.ok(shape({
assert.isTrue(shape({
a: '1',
b: 2
}));
Expand All @@ -177,7 +177,7 @@ describe('validators', function() {
})
});

assert.ok(shape({
assert.isTrue(shape({
a: {
b: 'test'
}
Expand All @@ -196,8 +196,8 @@ describe('validators', function() {

it('should return validator function instead of running it if no arg is passed to type validator', function() {
var validatorFn = validators.bool();
assert.ok(core.isFunction(validatorFn));
assert.ok(validatorFn(true));
assert.isTrue(core.isFunction(validatorFn));
assert.isTrue(validatorFn(true));
assert.ok(validatorFn('true') instanceof Error);
});

Expand Down