Socket
Socket
Sign inDemoInstall

hayaan

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hayaan

Ruby's RSpec-inspired scoped lazy variables for Jest, with native TypeScript support.


Version published
Maintainers
1
Install size
405 kB
Created

Readme

Source

hayaan

Ruby's RSpec-inspired scoped lazy variables for Jest, with native TypeScript support.

Comparison

Installation

npm install --save-dev hayaan / yarn add --dev hayaan

Usage

import dyn from "hayaan";

const sum = (a, b) => a + b;

describe("implementation", () => {
  const a = dyn(5);
  const b = dyn(3);
  const total = dyn(() => sum(a.value, b.value));

  it("sums up", () => expect(total.value).toEqual(8));
  
  describe("with b changed", () => {
    b.value = 10;
    it("sums up", () => expect(total.value).toEqual(15));
  })

  describe("with both changed", () => {
    a.value = 1;
    b.value = -2;
    it("still sums up", () => expect(total.value).toEqual(-1));
  });

  describe("with even the function changed", () => {
    total.deferredValue = () => sum(-a.value, b.value);
    it("uses the new function", () => expect(total.value).toEqual(-2));
    
    describe("and a changed", () => {
      a.value = 1;
      it("uses the right values", () => expect(total.value).toEqual(2));
    })
  });
})

Debugging

  • Make sure <variable>.value = ... calls are outside the it blocks
    • hayaan uses beforeEach and afterEach under the hood, which only work on higher level than individual tests

Credits

Inspired by https://github.com/tatyshev/given2 and https://gist.github.com/nerdcave/4418ca2c787f28c6cb30b7c96d7af1fe

FAQs

Last updated on 05 Apr 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc