1.4.2 • Published 3 years ago

hayaan v1.4.2

Weekly downloads
5
License
MIT
Repository
-
Last release
3 years ago

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

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

4 years ago

1.0.1

4 years ago