import { parse } from 'compiler/parser/index' import { extend } from 'shared/util' import { baseOptions } from 'web/compiler/index' describe('parser', () => { it('simple element', () => { const ast = parse('

hello world

', baseOptions) expect(ast.tag).toBe('h1') expect(ast.plain).toBe(true) expect(ast.children[0].text).toBe('hello world') }) it('interpolation in element', () => { const ast = parse('

{{msg}}

', baseOptions) expect(ast.tag).toBe('h1') expect(ast.plain).toBe(true) expect(ast.children[0].expression).toBe('_s(msg)') }) it('child elements', () => { const ast = parse('', baseOptions) expect(ast.tag).toBe('ul') expect(ast.plain).toBe(true) expect(ast.children[0].tag).toBe('li') expect(ast.children[0].plain).toBe(true) expect(ast.children[0].children[0].text).toBe('hello world') expect(ast.children[0].parent).toBe(ast) }) it('unary element', () => { const ast = parse('
', baseOptions) expect(ast.tag).toBe('hr') expect(ast.plain).toBe(true) expect(ast.children.length).toBe(0) }) it('svg element', () => { const ast = parse('hello world', baseOptions) expect(ast.tag).toBe('svg') expect(ast.ns).toBe('svg') expect(ast.plain).toBe(true) expect(ast.children[0].tag).toBe('text') expect(ast.children[0].children[0].text).toBe('hello world') expect(ast.children[0].parent).toBe(ast) }) it('camelCase element', () => { const ast = parse('

hello world

', baseOptions) expect(ast.tag).toBe('MyComponent') expect(ast.plain).toBe(true) expect(ast.children[0].tag).toBe('p') expect(ast.children[0].plain).toBe(true) expect(ast.children[0].children[0].text).toBe('hello world') expect(ast.children[0].parent).toBe(ast) }) it('forbidden element', () => { // style const styleAst = parse('', baseOptions) expect(styleAst.tag).toBe('style') expect(styleAst.plain).toBe(true) expect(styleAst.forbidden).toBe(true) expect(styleAst.children[0].text).toBe('error { color: red; }') expect('Templates should only be responsbile for mapping the state').toHaveBeenWarned() // script const scriptAst = parse('', baseOptions) expect(scriptAst.tag).toBe('script') expect(scriptAst.plain).toBe(false) expect(scriptAst.forbidden).toBe(true) expect(scriptAst.children[0].text).toBe('alert("hello world!")') expect('Templates should only be responsbile for mapping the state').toHaveBeenWarned() }) it('not contain root element', () => { parse('hello world', baseOptions) expect('Component template should contain exactly one root element').toHaveBeenWarned() }) it('warn