Skip to content

Commit

Permalink
linted function(
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Trecenti committed Jan 21, 2014
1 parent f4c95d8 commit cb7f1b6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion spec/validators/integer-validator-spec.js
@@ -1,7 +1,7 @@
describe('ko.validators.integerValidator', function () {
var validator;

beforeEach(function() {
beforeEach(function () {
validator = ko.validators.integerValidator('Must be a number.');
});

Expand Down
12 changes: 6 additions & 6 deletions spec/validators/invalid-chars-validator-spec.js
@@ -1,29 +1,29 @@
describe('ko.validators.invalidCharsValidator', function () {
var validator;

beforeEach(function() {
beforeEach(function () {
validator = ko.validators.invalidCharsValidator(['a', 'b'], "Must not contain 'a' nor 'b'.");
});

it('passes when the value does not contain invalid chars', function() {
it('passes when the value does not contain invalid chars', function () {
expect(validator.validate('foo').isValid).toBe(true);
});

it('fails when the value does contain invalid chars', function() {
it('fails when the value does contain invalid chars', function () {
expect(validator.validate('foao').isValid).toBe(false);
});

it('passes with an empty string', function() {
it('passes with an empty string', function () {
expect(validator.validate('')).toEqual({ isValid: true });
});

it('works with spaces', function() {
it('works with spaces', function () {
validator = ko.validators.invalidCharsValidator([' ']);
expect(validator.validate('fo o').isValid).toBe(false);
expect(validator.validate('foo').isValid).toBe(true);
});

it('has correct message on failure', function() {
it('has correct message on failure', function () {
expect(validator.validate('fooa')).toEqual({
isValid: false,
message: "Must not contain 'a' nor 'b'."
Expand Down
12 changes: 6 additions & 6 deletions spec/validators/max-length-validator-spec.js
@@ -1,26 +1,26 @@
describe('ko.validators.maxLengthValidator', function() {
describe('ko.validators.maxLengthValidator', function () {
var validator, result;

beforeEach(function() {
beforeEach(function () {
validator = ko.validators.maxLengthValidator(5, 'Cannot be longer than 5 characters.');
});

it('should pass if the length is in the limit', function() {
it('should pass if the length is in the limit', function () {
result = validator.validate('foo');
expect(result).toEqual({ isValid: true });
});

it('should check the length of an integer', function() {
it('should check the length of an integer', function () {
result = validator.validate(123);
expect(result.isValid).toBe(true);
});

it('should fail if the length is not in the limit', function() {
it('should fail if the length is not in the limit', function () {
result = validator.validate('foo-bar');
expect(result.isValid).toBe(false);
});

it('should have correct message on failure', function() {
it('should have correct message on failure', function () {
result = validator.validate('foo-bar');
expect(result.message).toBe('Cannot be longer than 5 characters.');
});
Expand Down
20 changes: 10 additions & 10 deletions spec/validators/range-validator-spec.js
@@ -1,46 +1,46 @@
describe('ko.validators.rangeValidator', function() {
describe('ko.validators.rangeValidator', function () {
var validator, result;

beforeEach(function() {
beforeEach(function () {
validator = ko.validators.rangeValidator(1, 10, 'Must be between 1 and 10.');
});

it('should pass if value is a number within range', function() {
it('should pass if value is a number within range', function () {
result = validator.validate(5);
expect(result.isValid).toBe(true);
});

it('should pass if value is a string within range', function() {
it('should pass if value is a string within range', function () {
result = validator.validate('5');
expect(result.isValid).toBe(true);
});

it('should fail if not a number', function() {
it('should fail if not a number', function () {
result = validator.validate('10a');
expect(result.isValid).toBe(false);
});

it('should fail if not an integer', function() {
it('should fail if not an integer', function () {
result = validator.validate('9.5');
expect(result.isValid).toBe(false);
});

it('should fail if less than range', function() {
it('should fail if less than range', function () {
result = validator.validate(0);
expect(result.isValid).toBe(false);
});

it('should fail if greater than range', function() {
it('should fail if greater than range', function () {
result = validator.validate(11);
expect(result.isValid).toBe(false);
});

it('should not provide error message when valid', function() {
it('should not provide error message when valid', function () {
result = validator.validate(10);
expect(result).toEqual({ isValid: true });
});

it('should provide a meaningful error message when not valid', function() {
it('should provide a meaningful error message when not valid', function () {
result = validator.validate(0);
expect(result).toEqual({
isValid: false,
Expand Down
10 changes: 5 additions & 5 deletions spec/validators/required-validator-spec.js
Expand Up @@ -13,31 +13,31 @@ describe('ko.validators.requiredValidator', function () {
});
});

it('is invalid if null', function() {
it('is invalid if null', function () {
result = validator.validate(null);
expect(result).toEqual({
isValid: false,
message: 'Field Name is required.'
});
});

it('is invalid if undefined', function() {
it('is invalid if undefined', function () {
result = validator.validate(undefined);
expect(result).toEqual({
isValid: false,
message: 'Field Name is required.'
});
});

it('is invalid if false', function() {
it('is invalid if false', function () {
result = validator.validate(false);
expect(result).toEqual({
isValid: false,
message: 'Field Name is required.'
});
});

it('is invalid if empty array', function() {
it('is invalid if empty array', function () {
result = validator.validate([]);
expect(result).toEqual({
isValid: false,
Expand All @@ -60,7 +60,7 @@ describe('ko.validators.requiredValidator', function () {
expect(result).toEqual({ isValid: true });
});

it('is valid if not empty', function() {
it('is valid if not empty', function () {
result = validator.validate('value');
expect(result).toEqual({ isValid: true });
});
Expand Down

0 comments on commit cb7f1b6

Please sign in to comment.