Comments (12)
I think this is a great idea, I'd be interested in a PR ☺
from vue-test-utils.
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.
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.
from vue-test-utils.
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.
from vue-test-utils.
@rowanu any luck with this? Would be a good feature for snapshot testing.
from vue-test-utils.
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.
Hi @rowanu. Have you looked into this anymore?
from vue-test-utils.
@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.
@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.
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)
- `RouterLink.useLink` is missing when using `RouterLinkStub`. HOT 3
- Test child component, which is the root element HOT 3
- Computed value does not update when data updates
- isVisible() not seeing display: none using vitest with jsdom HOT 4
- Testing component with onBeforeRouteLeave hook raising "No active route record was found" warning HOT 1
- vue2 引入 element2. 页面存在table 表格 jest 测试报错 HOT 1
- *.svg?inline issues
- Errors in `setup()` are silent if `render()` throws an error HOT 6
- Check style changes on hover HOT 1
- setData on writable computed property does not seem to work as it does in VTU.1
- classes documentation
- Support Vue 2.7.16 HOT 2
- Vue test utils not updating template when testing composables
- TypeError: $setup.mergeProps is not a function
- Data property is already defined in Props. HOT 1
- Unable to use vitest spy within vue/nuxt 3 component methods. HOT 3
- `findComponent` doesn't find anything when using `@vue/compat` HOT 1
- Components with TS generic HOT 1
- event.keyCode is deprecated
- Change mocks mid-test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-test-utils.