How to use the vue-template-compiler.compileToFunctions function in vue-template-compiler

To help you get started, we’ve selected a few vue-template-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-test-utils / packages / test-utils / dist / vue-test-utils.js View on Github external
if (originalComponents[stub]) {
        // Remove cached constructor
        delete originalComponents[stub]._Ctor;
        if (typeof stubs[stub] === 'string') {
          components[stub] = createStubFromString(stubs[stub], originalComponents[stub]);
        } else {
          components[stub] = Object.assign({}, stubs[stub],
            {name: originalComponents[stub].name});
        }
      } else {
        if (typeof stubs[stub] === 'string') {
          if (!vueTemplateCompiler.compileToFunctions) {
            throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
          }
          components[stub] = Object.assign({}, vueTemplateCompiler.compileToFunctions(stubs[stub]));
        } else {
          components[stub] = Object.assign({}, stubs[stub]);
        }
      }
      // ignoreElements does not exist in Vue 2.0.x
      if (Vue.config.ignoredElements) {
        Vue.config.ignoredElements.push(stub);
      }
    });
  }
github vuejs / vue-test-utils / test / specs / wrapper / text.spec.js View on Github external
it('returns trimmed text content of wrapper node', () => {
    const text = 'test text prop'
    const compiled = compileToFunctions(`
      <div>
      ${text}
    </div>`)
    const wrapper = mountingMethod(compiled)

    expect(wrapper.text()).to.equal(text)
  })
})
github vuejs / vue-test-utils / test / specs / wrapper-array / isEmpty.spec.js View on Github external
it('returns false if node contains other nodes', () =&gt; {
    const compiled = compileToFunctions('<div><span><p></p><p></p></span></div>')
    const wrapper = mountingMethod(compiled)

    expect(wrapper.findAll('span').isEmpty()).to.equal(false)
  })
github vuejs / vue-test-utils / test / specs / wrapper / findAll.spec.js View on Github external
it('throws an error when ref selector is called on a wrapper that is not a Vue component', () =&gt; {
    const compiled = compileToFunctions('<div><a href="/"></a></div>')
    const wrapper = mountingMethod(compiled)
    const a = wrapper.find('a')
    const message =
      '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers'
    const fn = () =&gt; a.findAll({ ref: 'foo' })
    expect(fn)
      .to.throw()
      .with.property('message', message)
  })
github vuejs / vue-test-utils / test / specs / wrapper / attributes.spec.js View on Github external
it('returns true if wrapper contains attribute matching value', () =&gt; {
    const attribute = 'attribute'
    const value = 'value'
    const compiled = compileToFunctions(`<div></div>`)
    const wrapper = mountingMethod(compiled)
    expect(wrapper.attributes()).to.eql({ attribute: value })
  })
github vuetifyjs / vuetify / packages / vuetify / src / components / VAutocomplete / __tests__ / VAutocomplete2.spec.ts View on Github external
it('should not hide menu when no data but has no-data slot', async () =&gt; {
    const wrapper = mountFunction({
      propsData: {
        combobox: true,
      },
      slots: {
        'no-data': [compileToFunctions('<span>show me</span>')],
      },
    })

    const input = wrapper.find('input')
    input.trigger('focus')
    await wrapper.vm.$nextTick()
    expect(wrapper.vm.menuCanShow).toBe(true)
  })
github vuejs / vue-test-utils / test / integration / specs / mount / wrapper / hasProp.spec.js View on Github external
it('throws an error if called on a non vm wrapper', () =&gt; {
    const compiled = compileToFunctions('<div><p></p></div>')
    const p = mount(compiled).findAll('p').at(0)
    const message = 'wrapper.hasProp() must be called on a Vue instance'
    expect(() =&gt; p.hasProp('no-prop', 'value')).to.throw(Error, message)
  })
github vuejs / vue-test-utils / test / specs / wrapper / update.spec.js View on Github external
it('updates slot components', () =&gt; {
    if (mountingMethod.name === 'shallow') return
    const SlotComponent = compileToFunctions('<div></div>')
    const Parent = {
      template: `
        
        <div></div>
      
      `,
      props: {
        on: {
          default: false,
          type: Boolean
        }
      },
      components: {
        SlotComponent
      }
    }
github vuejs / vue-test-utils / test / integration / specs / shallow / ShallowWrapper / find.spec.js View on Github external
it.skip('returns Wrapper of elements matching selector when descendant combinator passed', () =&gt; {
    const compiled = compileToFunctions('<div><ul><li>list</li>item<li></li></ul></div>')
    const wrapper = shallow(compiled)
    expect(wrapper.find('div li')).to.be.instanceOf(ShallowWrapper)
  })
github vuejs / vue-test-utils / packages / server-test-utils / dist / vue-server-test-utils.js View on Github external
function createVNodes (
  vm,
  slotValue,
  name
) {
  var el = vueTemplateCompiler.compileToFunctions(
    ("<div><template slot="+ name +">" + slotValue + "</template></div>")
  );
  var _staticRenderFns = vm._renderProxy.$options.staticRenderFns;
  var _staticTrees = vm._renderProxy._staticTrees;
  vm._renderProxy._staticTrees = [];
  vm._renderProxy.$options.staticRenderFns = el.staticRenderFns;
  var vnode = el.render.call(vm._renderProxy, vm.$createElement);
  vm._renderProxy.$options.staticRenderFns = _staticRenderFns;
  vm._renderProxy._staticTrees = _staticTrees;
  return vnode.children[0]
}