]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/data/validator/Format.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / data / validator / Format.js
CommitLineData
6527f429
DM
1describe("Ext.data.validator.Format", function() {\r
2 \r
3 var v;\r
4 \r
5 function validate(value, matcher) {\r
6 v = new Ext.data.validator.Format({\r
7 matcher: matcher\r
8 });\r
9 return v.validate(value);\r
10 }\r
11 \r
12 afterEach(function() {\r
13 v = null;\r
14 });\r
15 \r
16 it("should throw an exception if a matcher is not configured", function() {\r
17 expect(function() {\r
18 v = new Ext.data.validator.Format();\r
19 }).toThrow(); \r
20 });\r
21 \r
22 describe("invalid values", function() {\r
23 it("should not validate if the value does match the matcher re", function() {\r
24 expect(validate('foo', /^bar$/)).toBe(v.getMessage());\r
25 });\r
26 });\r
27 \r
28 describe("valid values", function() {\r
29 it("should validate if the value matches the matcher re", function() {\r
30 expect(validate('bar', /^bar$/)).toBe(true);\r
31 });\r
32 });\r
33 \r
34 describe("messages", function() {\r
35 it("should accept a custom message", function() {\r
36 v = new Ext.data.validator.Format({\r
37 message: 'Foo',\r
38 matcher: /^foo$/\r
39 });\r
40 expect(v.validate('bar')).toBe('Foo');\r
41 });\r
42 });\r
43 \r
44 describe("runtime changes", function() {\r
45 it("should be able to have a new matcher applied", function() {\r
46 v = new Ext.data.validator.Format({\r
47 matcher: /^foo/\r
48 });\r
49 expect(v.validate('bar')).toBe(v.getMessage());\r
50 v.setMatcher(/^bar/);\r
51 expect(v.validate('bar')).toBe(true);\r
52 });\r
53 });\r
54 \r
55});\r