-
Notifications
You must be signed in to change notification settings - Fork 820
/
Copy pathreject-validation.spec.ts
39 lines (34 loc) · 1.12 KB
/
reject-validation.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { ValidationError } from './../../src/validation/ValidationError';
import { Contains } from '../../src/decorator/decorators';
import { Validator } from '../../src/validation/Validator';
class MyClass {
@Contains('hello', {
message: '$value is not valid. Your string must contain a hello word',
})
someProperty: string;
}
describe('validateOrReject()', () => {
let validator: Validator;
let model: MyClass;
beforeEach(() => {
validator = new Validator();
model = new MyClass();
});
it('should resolve promise when no error', () => {
expect.assertions(1);
model.someProperty = 'hello world';
return validator.validateOrReject(model).then(args => {
expect(args).toBeUndefined();
});
});
it('should reject promise on error', () => {
expect.assertions(2);
model.someProperty = 'hell no world';
return validator.validateOrReject(model).catch((errors: ValidationError[]) => {
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
contains: 'hell no world is not valid. Your string must contain a hello word',
});
});
});
});