Skip to content

Add API for custom time functions implementation #310

@movpushmov

Description

@movpushmov

Proposal

Now patronum delay, interval, debounce, time works with global time functions (window.setTimeout, window.setInterval, window.Date.now) what make testing of some features impossible. The solution is create API where developer can manually set implementations of setTimeout/setInterval

Someting like this:

const $timers = createStore({ setTimeout: (cb) => cb() });

const startDelay = createEvent();
const triggered = delay({ source: startDelay, timeout: 200,  timers: $timers });

Motivation

  1. Developer can set their own implementations of time functions (this make testing very easy)
  2. This solution much better than jest fake timers, 'cause it can't create race condition even in theory

Related links:

  1. Jest mock race condition
  2. Jest async race condition

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCSome new feature that should be discussed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions