-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
HTMLButtonElement.test.ts
91 lines (73 loc) · 2.38 KB
/
HTMLButtonElement.test.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import Window from '../../../src/window/Window';
import Document from '../../../src/nodes/document/Document';
import HTMLButtonElement from '../../../src/nodes/html-button-element/HTMLButtonElement';
describe('HTMLButtonElement', () => {
let window: Window;
let document: Document;
let element: HTMLButtonElement;
beforeEach(() => {
window = new Window();
document = window.document;
element = <HTMLButtonElement>document.createElement('button');
});
describe('get value()', () => {
it(`Returns the attribute "value".`, () => {
element.setAttribute('value', 'VALUE');
expect(element.value).toBe('VALUE');
});
});
describe('set value()', () => {
it(`Sets the attribute "value".`, () => {
element.value = 'VALUE';
expect(element.getAttribute('value')).toBe('VALUE');
});
});
describe(`get disabled()`, () => {
it('Returns attribute value.', () => {
expect(element.disabled).toBe(false);
element.setAttribute('disabled', '');
expect(element.disabled).toBe(true);
});
});
describe(`set disabled()`, () => {
it('Sets attribute value.', () => {
element.disabled = true;
expect(element.getAttribute('disabled')).toBe('');
});
});
describe('get type()', () => {
it(`Defaults to "submit".`, () => {
expect(element.type).toBe('submit');
});
it(`Returns the attribute "type".`, () => {
element.setAttribute('type', 'menu');
expect(element.type).toBe('menu');
});
it(`Sanitizes the value before returning.`, () => {
element.setAttribute('type', 'reset');
expect(element.type).toBe('reset');
element.setAttribute('type', 'button');
expect(element.type).toBe('button');
element.setAttribute('type', 'submit');
expect(element.type).toBe('submit');
element.setAttribute('type', 'MeNu');
expect(element.type).toBe('menu');
element.setAttribute('type', 'foobar');
expect(element.type).toBe('submit');
});
});
describe('set type()', () => {
it(`Sets the attribute "type" after sanitizing.`, () => {
element.type = 'SuBmIt';
expect(element.getAttribute('type')).toBe('submit');
element.type = 'reset';
expect(element.getAttribute('type')).toBe('reset');
element.type = 'button';
expect(element.getAttribute('type')).toBe('button');
element.type = 'menu';
expect(element.getAttribute('type')).toBe('menu');
element.type = null;
expect(element.getAttribute('type')).toBe('submit');
});
});
});