import { parseComponent } from 'sfc/parser' describe('Single File Component parser', () => { it('should parse', () => { const res = parseComponent(`
`) expect(res.template.content.trim()).toBe('
hi
') expect(res.styles.length).toBe(4) expect(res.styles[0].src).toBe('./test.css') expect(res.styles[1].lang).toBe('stylus') expect(res.styles[1].scoped).toBe(true) expect(res.styles[1].content.trim()).toBe('h1\n color red\nh2\n color green') expect(res.styles[2].module).toBe(true) expect(res.styles[3].attrs['bool-attr']).toBe(true) expect(res.styles[3].attrs['val-attr']).toBe('test') expect(res.script.content.trim()).toBe('export default {}') }) it('should parse template with closed input', () => { const res = parseComponent(` `) expect(res.template.content.trim()).toBe('') }) it('should handle nested template', () => { const res = parseComponent(` `) expect(res.template.content.trim()).toBe('
') }) it('pad content', () => { const res = parseComponent(` `.trim(), { pad: true }) expect(res.script.content).toBe(Array(3 + 1).join('//\n') + '\nexport default {}\n') expect(res.styles[0].content).toBe(Array(6 + 1).join('\n') + '\nh1 { color: red }\n') }) it('should handle template blocks with lang as special text', () => { const res = parseComponent(` `) expect(res.template.content.trim()).toBe(`div\n h1(v-if='1 < 2') hello`) }) it('should handle component contains "<" only', () => { const res = parseComponent(` `) expect(res.template.content.trim()).toBe(`<`) }) it('should handle custom blocks without parsing them', () => { const res = parseComponent(` Hello Hello export default function simple (vm) { describe('Hello', () => { it('should display Hello', () => { this.vm.$refs.button.$el.innerText.should.equal('Hello') })) })) } `) expect(res.customBlocks.length).toBe(3) const simpleExample = res.customBlocks[0] expect(simpleExample.type).toBe('example') expect(simpleExample.content.trim()).toBe('Hello') expect(simpleExample.attrs.name).toBe('simple') const withProps = res.customBlocks[1] expect(withProps.type).toBe('example') expect(withProps.content.trim()).toBe('Hello') expect(withProps.attrs.name).toBe('with props') const simpleTest = res.customBlocks[2] expect(simpleTest.type).toBe('test') expect(simpleTest.content.trim()).toBe(`export default function simple (vm) { describe('Hello', () => { it('should display Hello', () => { this.vm.$refs.button.$el.innerText.should.equal('Hello') })) })) }`) expect(simpleTest.attrs.name).toBe('simple') expect(simpleTest.attrs.foo).toBe('bar') }) // Regression #4289 it('accepts nested template tag', () => { const raw = `
` const res = parseComponent(``) expect(res.template.content.trim()).toBe(raw) }) it('should not hang on trailing text', () => { const res = parseComponent(`