-
-
Notifications
You must be signed in to change notification settings - Fork 474
Expand file tree
/
Copy pathform-method-require.spec.js
More file actions
64 lines (55 loc) · 2.23 KB
/
Copy pathform-method-require.spec.js
File metadata and controls
64 lines (55 loc) · 2.23 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const HTMLHint = require('../../dist/htmlhint.js').HTMLHint
const ruleId = 'form-method-require'
const ruleOptions = {}
ruleOptions[ruleId] = true
describe(`Rules: ${ruleId}`, () => {
it('Form with method="get" should not result in an error', () => {
const code = '<form method="get"></form>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(0)
})
it('Form with method="post" should not result in an error', () => {
const code = '<form method="post"></form>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(0)
})
it('Form with method="dialog" should not result in an error', () => {
const code = '<form method="dialog"></form>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(0)
})
it('Form without method attribute should result in an error', () => {
const code = '<form></form>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(1)
expect(messages[0].rule.id).toBe(ruleId)
expect(messages[0].line).toBe(1)
expect(messages[0].col).toBe(6)
expect(messages[0].type).toBe('warning')
expect(messages[0].message).toBe(
'The method attribute must be present on <form> elements.'
)
})
it('Form with invalid method value should result in an error', () => {
const code = '<form method="invalid"></form>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(1)
expect(messages[0].rule.id).toBe(ruleId)
expect(messages[0].line).toBe(1)
expect(messages[0].col).toBe(6)
expect(messages[0].type).toBe('warning')
expect(messages[0].message).toBe(
'The method attribute of <form> must have a valid value: "get", "post", or "dialog".'
)
})
it('Form with uppercase method value should not result in an error', () => {
const code = '<form method="POST"></form>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(0)
})
it('Other elements should not be affected by this rule', () => {
const code = '<div>Not a form</div><input type="text">'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(0)
})
})