extract-props.spec.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import extractProps from '../lib/extract-props'
  2. describe('when extracting props with props. prefix from functional template content', () => {
  3. it('extracts interpolated props ', () => {
  4. const content = '<div> {{props.msg1 }} {{props.msg2}}</div>'
  5. expect(extractProps(content)).toBe("[ 'msg1', 'msg2' ]")
  6. })
  7. it('extracts props used in v-for', () => {
  8. const content = '<div v-for="bar in props.foo.bar"> {{ bar }}} </div>'
  9. expect(extractProps(content)).toBe("[ 'foo' ]")
  10. })
  11. it('extracts props with nested structure', () => {
  12. const content = '<div> {{props.msg1.foo }} {{props.msg1.bar}}</div>'
  13. expect(extractProps(content)).toBe("[ 'msg1' ]")
  14. })
  15. it('extracts callback props', () => {
  16. const content = '<button @click="props.onClick(props.msg)">{{props.msg.title}}</button>'
  17. expect(extractProps(content)).toBe("[ 'onClick', 'msg' ]")
  18. })
  19. it('extracts array props', () => {
  20. const content = '<div>{{props.msg[title]}}</div>'
  21. expect(extractProps(content)).toBe("[ 'msg' ]")
  22. })
  23. })