Skip to content

Instantly share code, notes, and snippets.

@krukru
Created April 25, 2019 07:15
Show Gist options
  • Save krukru/0ac16e15cd793334051a96bd2da6d22f to your computer and use it in GitHub Desktop.
Save krukru/0ac16e15cd793334051a96bd2da6d22f to your computer and use it in GitHub Desktop.
// services/validators/ExampleValidator.js
export class ExampleValidator {
validateFoo(input) {
return input.length === 5;
}
}
//test/services/validators/ExampleValidator.test.js
import {ExampleValidator} from '@/services/validators/ExampleValidator';
describe('ExampleValidator', function () {
let validator;
beforeEach(function () {
validator = new ExampleValidator();
});
const testCases = [
[5, false],
[undefined, false],
[null, false],
['', false],
['5', false],
[12345, false],
['12345', true],
];
testCases.forEach((testCase) => {
const [input, expected] = testCase;
test('validateFoo', () => {
const result = validator.validateFoo(input);
expect(result).toBe(expected);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment