🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

brjs-clock

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brjs-clock

A clock for testing.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

brjs-clock

Build Status

brjs-clock is a library that provides a Clock class that allows to control the flow of time for a testing environment.

Installation

To install brjs-clock use:

npm install brjs-clock

Code Example

'use strict';

var clock = require('brjs-clock');
var expect = require('expectations');

describe('Clock', function() {
	var timeoutCounter, intervalCounter;

	beforeEach(function() {
		clock = new Clock();
		clock.install();

		timeoutCounter = 0;
		intervalCounter = 0;

		setTimeout(function() {
			timeoutCounter++;
		}, 1000);

		setInterval(function() {
			intervalCounter++;
		}, 2000);
	});

	afterEach(function() {
		clock.uninstall();
	});

	it('fires the timer only once', function() {
		clock.tick(999);
		expect(timeoutCounter).toBe(0);
		clock.tick(1);
		expect(timeoutCounter).toBe(1);
		clock.tick(1000);
		expect(timeoutCounter).toBe(1);
	});

	it('fires at each interval', function() {
		clock.tick(2000);
		expect(intervalCounter).toBe(1);
		clock.tick(2000);
		expect(intervalCounter).toBe(2);
	});
});

Keywords

clock

FAQs

Package last updated on 25 Nov 2015

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