-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data fields of type date are not set over wrapper.setData. #818
Comments
Thanks for the detailed bug report, and sorry for the issues this has caused you. Yes this is a bug with Vue Test Utils, and is part of a wider bug we have with asynchrnous DOM updates. A temporary workaround if to run your tests asynchronously: it("allows setting selectedDate", () => {
let wrapper = shallow(demo, {sync: false});
let testDate = new Date()
wrapper.setData({selectedDate: testDate})
setTimeout(() => {
wrapper.vm.selectedDate.should.be.equal(testDate)
done()
})
}); |
@eddyerburgh, thank you for the feedback. I have updated the pen to add an asynchronous version of the test. Both fail, the original synchronous and the newly added asynchronous. Am I missing something basic? |
So there are two issues here—firstly the sync issue. Secondly, it appears there's a bug when you use the component returned from I'm closing the original sync issue in favor of #676 |
@eddyerburgh Thanks for the feedback. I don't really get what you mean by saying
could you please elaborate? |
Sorry, I wrote the wrong variable name. In your example you have a |
Hi, @eddyerburgh, no luck with options object either. It does not work, see the updated pen. However, I think, I now see where we are talking past each other. My issue is about setting As I wrote in my first post, I think the reason is that vue-test-utils tries to merge |
Version
1.0.0-beta.20
Reproduction link
https://codepen.io/sparlampe/pen/wxBqOy
Steps to reproduce
In a unit test try to use
wrapper.setData
to set a field of type date like sowrapper.setData(someDateField: new Date())
What is expected?
someDateField
should be equal to the current dateWhat is actually happening?
if the default value is
undefined
, aftersetDate
is executed, the field has value{}
.This seems to happen because of the merging of objects in the vue-test-utils code. At some point vue-test-util calculates the source object and the target object.
The target object is calculated as follows:
Object(vm.someDateField)
which gives{}
ifsomeDateField
is initiallyundefined
. The the source object is explored for keys like so:Object.keys(new Date())
, which gives[]
.So eventually we have an empty target object with no fields from the source object to be transferred to the target.
The text was updated successfully, but these errors were encountered: