Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lolex

Package Overview
Dependencies
Maintainers
4
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lolex

Fake JavaScript timers

  • 2.7.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3M
decreased by-18.16%
Maintainers
4
Weekly downloads
 
Created

What is lolex?

The lolex npm package is a library for JavaScript that allows you to control and manipulate the passage of time. It can be particularly useful in testing environments where you want to simulate specific timing conditions without waiting for real time to pass. It allows you to mock the Date object, timers like setTimeout, setInterval, and setImmediate, as well as nextTick (in Node.js). This can help in creating deterministic tests for time-dependent code.

What are lolex's main functionalities?

Mocking Date

This feature allows you to mock the global Date object, so you can simulate any time you need for testing purposes.

const lolex = require('lolex');
const clock = lolex.install();
console.log(new Date()); // This will show the mocked date
clock.uninstall();

Timers

With lolex, you can simulate the behavior of JavaScript timers (setTimeout, setInterval, and setImmediate), allowing you to test timer-dependent code without real time delays.

const lolex = require('lolex');
const clock = lolex.install();
setTimeout(() => console.log('Timer called'), 1000);
clock.tick(1000); // Manually advance the clock
// 'Timer called' is printed to the console
clock.uninstall();

nextTick

This feature is specific to Node.js and allows you to control the process.nextTick queue, enabling the testing of code that uses nextTick to defer actions.

const lolex = require('lolex');
const clock = lolex.install({toFake: ['nextTick']});
process.nextTick(() => console.log('nextTick called'));
clock.runAll(); // Executes all scheduled nextTick callbacks
clock.uninstall();

Other packages similar to lolex

FAQs

Package last updated on 19 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc