Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
});
}
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)
})
})
it('returns false if node contains other nodes', () => {
const compiled = compileToFunctions('<div><span><p></p><p></p></span></div>')
const wrapper = mountingMethod(compiled)
expect(wrapper.findAll('span').isEmpty()).to.equal(false)
})
it('throws an error when ref selector is called on a wrapper that is not a Vue component', () => {
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 = () => a.findAll({ ref: 'foo' })
expect(fn)
.to.throw()
.with.property('message', message)
})
it('returns true if wrapper contains attribute matching value', () => {
const attribute = 'attribute'
const value = 'value'
const compiled = compileToFunctions(`<div></div>`)
const wrapper = mountingMethod(compiled)
expect(wrapper.attributes()).to.eql({ attribute: value })
})
it('should not hide menu when no data but has no-data slot', async () => {
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)
})
it('throws an error if called on a non vm wrapper', () => {
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(() => p.hasProp('no-prop', 'value')).to.throw(Error, message)
})
it('updates slot components', () => {
if (mountingMethod.name === 'shallow') return
const SlotComponent = compileToFunctions('<div></div>')
const Parent = {
template: `
<div></div>
`,
props: {
on: {
default: false,
type: Boolean
}
},
components: {
SlotComponent
}
}
it.skip('returns Wrapper of elements matching selector when descendant combinator passed', () => {
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)
})
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]
}