Skip to content

Commit 2b8586f

Browse files
committed
Add form validator tests
1 parent ba81d67 commit 2b8586f

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

client/validation/form.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const convertToFormErrors = (err) => {
66
return errors;
77
};
88

9-
// @todo #3:30min Add tests
109
export const createFormSchemaValidator = schema => (fields) => {
1110
try {
1211
schema.omit('_id').validator()(fields);

client/validation/form.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import SimpleSchema from 'simpl-schema';
2+
import {createFormSchemaValidator} from './form';
3+
import chai from 'chai';
4+
5+
chai.should();
6+
7+
describe('form validation', () => {
8+
const schema = new SimpleSchema({
9+
name: {type: String}
10+
});
11+
const validator = createFormSchemaValidator(schema);
12+
13+
it('should use schema validator', () => {
14+
const result = validator({});
15+
const expectedErrors = {name: 'Name is required'};
16+
result.should.deep.equal(expectedErrors);
17+
});
18+
19+
it('should return an empty object when no errors', () => {
20+
validator({name: 'asd'}).should.deep.equal({});
21+
});
22+
23+
it('should omit _id field', () => {
24+
const schemaWithId = new SimpleSchema({
25+
name: {type: String},
26+
_id: {type: String},
27+
});
28+
29+
createFormSchemaValidator(schemaWithId)({name: 'asd'}).should.deep.equal({});
30+
});
31+
});

nightwatch.conf.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
const SCREENSHOT_PATH = process.env.CIRCLE_ARTIFACTS || 'nightwatch-output/screenshots';
22

3-
// TODO add these to package.json
4-
// ,
5-
// "nightmare": "^2.10.0",
6-
// "nightwatch": "^0.9.19",
7-
// "selenium-server-standalone-jar": "3.8.1"
8-
93
module.exports = {
104
src_folders: [
115
'tests/fixtures'

0 commit comments

Comments
 (0)