Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

timecop causes jquery-ui-datepicker to not work until timecop is uninstalled #24

Open
matthargett opened this issue Feb 18, 2014 · 3 comments

Comments

@matthargett
Copy link

Ran into this conflict on our project. We're using the JQuery UI datepicker for a calendar control. After Timecop.install() is called, the datepicker will no longer "show". As soon as Timecop.uninstall() is called, the seemingly-batched show commands to the datepicker finally get sent and the calendar control shows.

Timecop.install();
$("#search_case_filed_start_date").datepicker("show"); // does not show, no exceptions or JS errors shown in browser
Timecop.uninstall(); // finally shows after uninstall
@jamesarosen
Copy link
Owner

Can you link to any places where datepicker might use setTimeout or similar?

Have you tried using Sinon's fake clock support?

@matthargett
Copy link
Author

Haven't tried Sinon -- we wanted to use Timecop on both the server and front-end JS side. We're using Timecop within Selenium.

The code within the jquery datepicker does indeed use setTimeout in one place, here:

        // deffered render of the years select (to avoid flashes on Firefox)
        if( inst.yearshtml ){
            origyearshtml = inst.yearshtml;
            setTimeout(function(){
                //assure that inst.yearshtml didn't change.
                if( origyearshtml === inst.yearshtml && inst.yearshtml ){
                    inst.dpDiv.find("select.ui-datepicker-year:first").replaceWith(inst.yearshtml);
                }
                origyearshtml = inst.yearshtml = null;
            }, 0);
        }

@jamesarosen
Copy link
Owner

Timecop doesn't modify the global setTimeout and setInterval implementations. It's possible that it should.

Sinon's date faking does and we've had good results with it in front-end testing (both in the browser and via PhantomJS). There is a sinon npm module. I'd give it a shot.

I'd be happy to take a pull request to fix this. I haven't actually abandoned this project, but I'm leaning towards deprecating it in favor of Sinon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants