Comments (3)
Currently I would use <DatePicker ref='datepicker' />
attribute so that I can refer to it at this.$refs.datePicker
and only test the props passing and event emit part.
For DatePicker
create an individual test, create a clone of the component and delete the mounted
function before test.
edit: attachToDocument:true
is needed in parent component
from avoriaz.
I never considered this use case and I'm not sure how to solve it.
Short term, I suggest testing dateInput using shallow
.
// Test that show props are passed to Datepicker when Dateinput has data show set to true
// Note: you need to give Datepicker a name for this to work
test('toogle DatePicker', t => {
let wrapper = shallow(DateInput);
wrapper.setData({ show: true });
t.true(wrapper.find(DatePicker)[0].vm.show)
});
This isn't a good solution, and I'm sorry but I'm not sure how to fix the problem. I'll detail it below.
from avoriaz.
The problem is that attachToDocument creates a div and passes that as the root of the component you are mounting. When the component is rendered it runs Datepicker
's mounted method and attaches it to the div we made (vm.$root.$el). Shortly after, the root components $el is updated with the result of the render function. The original div that has Datepicker
attached is then cut off, and is not possible to access from the root vm
.
In summary, attachToDocument is a hack to attach the instance to a document. Your component happens to not work because of that hack.
I'll have a think about how to fix this.
from avoriaz.
Related Issues (20)
- External JS files "not defined" HOT 1
- Can't get input value based on v-model HOT 2
- Migrating from Avoriaz to vue-test-utils HOT 1
- Testing props being passed to child components on mount HOT 2
- Test fails when trying to trigger click inside <router-view></router-view> HOT 1
- hasAttribute docs seem to be outdated HOT 1
- Returning undefined on wrapper.html() for a component with jade and vuex
- Tests disregard disabled attribute HOT 3
- How can I use shallow() for a component wrapped in a function within a class HOT 1
- Trigger not working with click
- Make children select work as it should HOT 1
- data() returns empty object HOT 2
- Trigger mouseover/mouseleave etc
- Is this project deprecated in favor of vue-test-utils now? HOT 2
- Scoped slots (slot-scope) issues HOT 3
- Suppress logged warning on calls to propsData() HOT 1
- vue-test-utils 1.0.0-beta.11 setData Error HOT 1
- vue-test-utils 1.0.0-beta.16 setData Error
- Can't find nested component with neither '.find' nor '.first' wrapper methods HOT 3
- How do you ensure a global is being set to child components from mount? HOT 1
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 avoriaz.