GithubHelp home page GithubHelp logo

jamesarosen / timecop.js Goto Github PK

View Code? Open in Web Editor NEW
126.0 9.0 27.0 280 KB

A Javascript library providing "time travel" and "time freezing" capabilities for testing. See also https://github.com/jtrupiano/timecop

License: MIT License

Ruby 4.21% JavaScript 94.02% CSS 1.77%

timecop.js's Introduction

What

A port of John Trupiano's awesome Timecop Ruby to Javascript.

How

Call Timecop.install() once to get started. This replaces Date with Timecop.MockDate. After that, you can travel through time at will.

Travel to the morning of October 17, 2010, and allow time to continue advancing:

Timecop.travel(new Date(2010, 10, 17, 11, 45));

Travel to the afternoon of January 21, 2012, and keep time frozen then:

Timecop.freeze(new Date(2012, 1, 21, 14, 30));

Return to the present:

Timecop.returnToPresent();

Finally, to uninstall Timecop and reinstate the native Date constructor:

Timecop.uninstall();

Contributing

See Contributing.md.

timecop.js's People

Contributors

jamesarosen avatar jwark avatar jasondew avatar hjdivad avatar jayzes avatar searls avatar

Stargazers

Tan Yeong Sheng avatar Emily Spencer avatar syte avatar Djamel B. avatar Jeremy W. Sherman avatar Mathieu Godart avatar cheezenaan avatar Michael Corrado avatar Scott Chamberlain avatar Bolaji Olajide avatar Jack avatar Dan Jesus avatar Matt Travi avatar DAVID RUPP JR. avatar Moaaz Ashour avatar Tachun Lin avatar Renn avatar Adam Fabicki avatar Eduardo Weiland avatar Changbai Li avatar Shogo Kawahara (bucyou) avatar Michael avatar Thomas Boyt avatar Paul Byrne avatar Joannou Ng avatar Mantas Norvaiša avatar Andre Vidic avatar Hugh Francis avatar taichi avatar Colin Dekker avatar Ryan LaBouve avatar Terin Stock avatar Sadjow Leão avatar Tyler Green avatar Corné Verbruggen avatar Alexey Efremov avatar Hirokazu Hata avatar Zhongliang Wang avatar Ryan Jelks avatar Nathan Hackley avatar Alex Pauly avatar Ming Liu avatar Arno Chauveau avatar Angus H. avatar timelyportfolio avatar Stefan Topfstedt avatar Brian Johnson avatar Stephan Ahlf avatar Bryan Clark avatar Fabien Franzen avatar Haruka Asakura avatar Daniel Taveras avatar Frédéric Mascaro avatar Michael Anthony avatar MB avatar Limian Wang avatar Nozim Mehrubonov avatar Josh Smith avatar Nicholas Palaniuk avatar Michael Arthur avatar Jillian Ada Burrows avatar  avatar Armand Abric avatar Petr Bela avatar Chee Yeo avatar Jonathan Maddison avatar Mike Li avatar  avatar Jonas Hermsmeier avatar Matteo Collina avatar Ancor Cruz avatar Thomas Walpole avatar Jordan Harband avatar Simon Højberg avatar Ryan LaNeve avatar Sam Shull avatar Matt Lehman avatar Alex F avatar Eliot Sykes avatar Ivan Kotelnikov avatar Monica Olinescu avatar Christopher Gooley avatar Brandon Ashworth avatar  avatar Randall Chin avatar Peter Ajtai avatar  avatar Ryan McGeary avatar Martin Vicen avatar Poro avatar Tom Leach avatar Bilawal Hameed avatar Paulo Gaspar avatar Austin avatar Brian Ewing avatar Alan Norton avatar Richard McCollister avatar Don Onwunumah avatar Brandon Skeen avatar Dan avatar

Watchers

 avatar Thomas Walpole avatar  avatar  avatar timelyportfolio avatar James Cloos avatar Michael Anthony avatar Lars Haßler avatar  avatar

timecop.js's Issues

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

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

Add JSLint

Create a Rake- or Makefile and add a JSLint task.

Timecop doesn't provide #setDate()

So after installing timecop and traveling, I have some code like this:

var inThirtyDays = new Date();
inThirtyDays.setDate(new Date().getDate() + 30);

Which, normally, would roll the date forward 30 days. However, if Date has been timecop'd, I instead get:

Result of expression 'inThirtyDays.setDate' [undefined] is not a function

Mock out browser's current timezone

Anyone here have experience with mocking out the browser's Timezone API? Timecop.travel works great but we have failing tests on our CI server because of the server's timezone

Integration with Timecop gem and rails?

Hi,

has somebody successfully integrated Timecop.js together with the original Timecop gem and rails before?

We have such code in our acceptance tests (using MiniTest and Capybara):

before do
  travel_to 'October 10, 2010'
end

after do
  Timecop.return
end

The problem is that our backend code is now behaving differently from our client code (in our case a jquery-ui datepicker) in this test. Maybe there is a way to inject the right javascript snippets in order to create the same behavior on the client side?

We have a yield :head in our application layout. Maybe this could be used to inject the JS using ActionView::Helpers::CaptureHelper.content_for ? But this is just a vague idea.

Any thoughts anybody?

package.json

main hasn't the version ("main": "timecop.js") but bower install it with version so, file is timecop-0.1.1 instead of timecop.js that is the library name called. Please, can you change the main to: "main": "timecop-0.1.1.js" ?? Thanks a lot!

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.