Giter Club home page Giter Club logo

Comments (12)

eddyerburgh avatar eddyerburgh commented on September 26, 2024

I think this is a great idea, I'd be interested in a PR ☺

from vue-test-utils.

rowanu avatar rowanu commented on September 26, 2024

Great. Have been having a think about it and wanted some input on the interface.

While including the component name is not too hard, if I keep it as HTML comments I don't know how to check for their presence (short of searching through the rendered HTML text, which I don't like).

If I render a <div/> with the appropriate id attribute (based on the component type property), it becomes trivial to assert if the components are present but am I making too many assumptions by rendering a div for each component? Something like this:

import { mount } from 'vue-test-utils'
import { expect } from 'chai'
// Contains an instance of the Foo component, with type "foo"
import App from './App.vue'

const wrapper = mount(App)
expect(wrapper.contains('div#foo')).to.equal(true)

Keep in mind I'm new to Vue, so let me know if I'm not being idomatic.

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on September 26, 2024

I think we should keep it as comments.

You can check that a component has rendered using this method -

import Child from '~/Child.vue'
import ComponentWithChild from '~/ComponentWithChild.vue'

const wrapper = shallow(ComponentWithChild)

expect(wrapper.find(Child).exists()).toBe(true)
expect(wrapper.findAll(Child).length).toEqual(1)

from vue-test-utils.

blocka avatar blocka commented on September 26, 2024

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on September 26, 2024

@blocka

import Child from '~/Child.vue'
import ComponentWithChild from '~/ComponentWithChild.vue'

const wrapper = shallow(ComponentWithChild)

expect(wrapper.find(Child).vm.someProp).toEqual('a value')

from vue-test-utils.

blocka avatar blocka commented on September 26, 2024

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on September 26, 2024

@rowanu any luck with this? Would be a good feature for snapshot testing.

from vue-test-utils.

rowanu avatar rowanu commented on September 26, 2024

Haven't had much chance, and need to learn a bit more about Vue. Still on my list of things to do.

Just want to make sure my understanding is correct: You said previously that you want to keep the child components rendered as comments, but want to use the usual find/findAll syntax (in your example); This means most of my modifications will likely be on the selectors (rather than the render), right?

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on September 26, 2024

Hi @rowanu. Have you looked into this anymore?

from vue-test-utils.

andycopley avatar andycopley commented on September 26, 2024

@eddyerburgh I've taken a brief look into this, and best I can produce are empty component stubs <my-component></my-component> in place of <!-- MyComponent -->. I've not gone too far into it, but Vue strips comments from rendering, so not sure how to complete this as discussed above.

from vue-test-utils.

eddyerburgh avatar eddyerburgh commented on September 26, 2024

@andycopley I believe you can set an option to stop comments being stripped by the template compiler. But I don't think comments can be a root vnode. Not 100% as I haven't looked into it.

Thanks for taking a look. I don't think adding components is a good option. We should either add the comments, or not add anything.

from vue-test-utils.

klarkc avatar klarkc commented on September 26, 2024

I think we can just leave the component in place, removing only the import of the component. Leaving the component with properties and so on. The normal Vue behavior is just to throw a warning that the component in the template does not exists. This way the template will be rendered as it is, not having to deal with comment transpilation.

I don't know how to implement this, but my guess is that this render function should render the component template instead of nothing.

Also we must know how this will impact the selectors and api methods, probabily some patches to handle not rendered templates, or exclusive methods to deal with stub components

from vue-test-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.