|
| 1 | +import {baseOptions} from "../platform-web-compiler/options"; |
| 2 | +import {parse} from "../vue3-template-compiler/parser"; |
| 3 | + |
| 4 | +describe('parser', () => { |
| 5 | + it('simple element', () => { |
| 6 | + const ast = parse('<h1>hello world</h1>', baseOptions); |
| 7 | + expect(ast.tag).toBe('h1'); |
| 8 | + expect(ast.plain).toBe(true); |
| 9 | + expect(ast.children[0].text).toBe('hello world'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('interpolation in element', () => { |
| 13 | + const ast = parse('<h1>{{msg}}</h1>', baseOptions); |
| 14 | + expect(ast.tag).toBe('h1'); |
| 15 | + expect(ast.plain).toBe(true); |
| 16 | + expect(ast.children[0].expression).toBe('_s(msg)'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('child elements', () => { |
| 20 | + const ast = parse('<ul><li>hello world</li></ul>', baseOptions); |
| 21 | + expect(ast.tag).toBe('ul'); |
| 22 | + expect(ast.plain).toBe(true); |
| 23 | + expect(ast.children[0].tag).toBe('li'); |
| 24 | + expect(ast.children[0].plain).toBe(true); |
| 25 | + expect(ast.children[0].children[0].text).toBe('hello world'); |
| 26 | + expect(ast.children[0].parent).toBe(ast); |
| 27 | + }); |
| 28 | + |
| 29 | + it('unary element', () => { |
| 30 | + const ast = parse('<hr>', baseOptions); |
| 31 | + expect(ast.tag).toBe('hr'); |
| 32 | + expect(ast.plain).toBe(true); |
| 33 | + expect(ast.children.length).toBe(0); |
| 34 | + }); |
| 35 | + |
| 36 | + it('camelCase element', () => { |
| 37 | + const ast = parse('<MyComponent><p>hello world</p></MyComponent>', baseOptions) |
| 38 | + expect(ast.tag).toBe('MyComponent') |
| 39 | + expect(ast.plain).toBe(true) |
| 40 | + expect(ast.children[0].tag).toBe('p') |
| 41 | + expect(ast.children[0].plain).toBe(true) |
| 42 | + expect(ast.children[0].children[0].text).toBe('hello world') |
| 43 | + expect(ast.children[0].parent).toBe(ast) |
| 44 | + }) |
| 45 | +}); |
0 commit comments