Coder Social home page Coder Social logo

Comments (3)

jackysee avatar jackysee commented on May 28, 2024 1

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.

eddyerburgh avatar eddyerburgh commented on May 28, 2024

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.

eddyerburgh avatar eddyerburgh commented on May 28, 2024

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)

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.