|
1 |
| -import { $ } from "../$"; |
2 |
| -import { IElement, render, tsx } from "springtype"; |
3 |
| - |
4 |
| -describe("General DOM manipulation", () => { |
5 |
| - |
6 |
| - it('can update children of a SpringType-created DOM element', () => { |
7 |
| - const el = render(<div>Check</div>) as IElement; |
8 |
| - $(el).html(<div>Check2</div>); |
9 |
| - expect(el.childNodes[0].textContent).toEqual('Check2'); |
10 |
| - }); |
11 |
| - |
12 |
| - it('can empty an element', () => { |
13 |
| - document.body.innerHTML = '<div>Test</div>'; |
14 |
| - $(document.body).empty(); |
15 |
| - expect(document.body.childNodes[0]).toBeFalsy(); |
16 |
| - }); |
17 |
| - |
18 |
| - it('can set an attribute', () => { |
19 |
| - $(document.body).attr('foo', 'bar'); |
20 |
| - expect(document.body.getAttribute('foo')).toEqual('bar'); |
21 |
| - }); |
22 |
| - |
23 |
| - it('can get an attribute', () => { |
24 |
| - $(document.body).attr('foo2', 'bar'); |
25 |
| - expect($(document.body).attr('foo2')).toEqual('bar'); |
26 |
| - }); |
27 |
| - |
28 |
| - it('can replace an element with another', () => { |
29 |
| - const divRef: any = {}; |
30 |
| - render(<div ref={divRef}>Check</div>, document.body) as IElement; |
31 |
| - divRef.current = $(divRef.current).replaceWith(<div tabIndex="2">Check2</div>); |
32 |
| - expect($(divRef.current).attr('tabIndex')).toEqual("2"); |
33 |
| - }); |
34 |
| - |
35 |
| - it('remove an element', () => { |
36 |
| - $(document.body).remove(); |
37 |
| - expect(document.body).toBeFalsy(); |
38 |
| - }); |
| 1 | +import { IElement, Ref, render, tsx } from 'springtype'; |
| 2 | +import { $ } from '..'; |
| 3 | + |
| 4 | +describe('General DOM manipulation', () => { |
| 5 | + it('can update children of a SpringType-created DOM element', () => { |
| 6 | + const el = render(<div>Check</div>) as IElement; |
| 7 | + $(el).html(<div>Check2</div>); |
| 8 | + expect(el.childNodes[0].textContent).toEqual('Check2'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('can empty an element', () => { |
| 12 | + document.body.innerHTML = '<div>Test</div>'; |
| 13 | + $(document.body).empty(); |
| 14 | + expect(document.body.childNodes[0]).toBeFalsy(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('can set an attribute', () => { |
| 18 | + $(document.body).attr('foo', 'bar'); |
| 19 | + expect(document.body.getAttribute('foo')).toEqual('bar'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('can get an attribute', () => { |
| 23 | + $(document.body).attr('foo2', 'bar'); |
| 24 | + expect($(document.body).attr('foo2')).toEqual('bar'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('can get an input value', () => { |
| 28 | + const inputRef: Ref = {}; |
| 29 | + render(<input ref={inputRef} value="123" />, document.body) as IElement; |
| 30 | + expect($(inputRef.current!).val()).toEqual('123'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('can set an input value', () => { |
| 34 | + const inputRef: Ref = {}; |
| 35 | + render(<input ref={inputRef} value="123" />, document.body) as IElement; |
| 36 | + $(inputRef.current!).val('345'); |
| 37 | + expect($(inputRef.current!).val()).toEqual('345'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('can get a checkbox checked value', () => { |
| 41 | + const inputRef: Ref = {}; |
| 42 | + render(<input ref={inputRef} type="checkbox" checked />, document.body) as IElement; |
| 43 | + expect($(inputRef.current!).val()).toEqual(true); |
| 44 | + }); |
| 45 | + |
| 46 | + it('can set a checkbox checked value', () => { |
| 47 | + const inputRef: Ref = {}; |
| 48 | + render(<input ref={inputRef} type="checkbox" />, document.body) as IElement; |
| 49 | + $(inputRef.current!).val(true); |
| 50 | + expect($(inputRef.current!).val()).toEqual(true); |
| 51 | + }); |
| 52 | + |
| 53 | + it('can replace an element with another', () => { |
| 54 | + const divRef: any = {}; |
| 55 | + render(<div ref={divRef}>Check</div>, document.body) as IElement; |
| 56 | + divRef.current = $(divRef.current).replaceWith(<input tabIndex="-2" />); |
| 57 | + expect($(divRef.current).attr('tabIndex')).toEqual('-2'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('remove an element', () => { |
| 61 | + $(document.body).remove(); |
| 62 | + expect(document.body).toBeFalsy(); |
| 63 | + }); |
39 | 64 | });
|
0 commit comments