1.0.2 • Published 6 years ago

ts-jasmine-immutable-matchers v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

ts-jasmine-immutable-matchers

Jasmine custom matchers for Immutablejs.

Installation

$ npm install --save-dev ts-jasmine-immutable-matchers

(I know, the module name is pretty long ¯_(ツ)_/¯)

Usage

Load the matchers in a beforeEach block.

import { matchers } from "ts-jasmine-immutable-matchers";

declare("Your Awesome Tests", () => {
  beforeEach(() => jasmine.addMatchers(matchers));
});

API

toBeImmutable

Asserts that the data structure is immutable.

import { List } from "immutable";

declare("Immutable", () => {
  it("is not immutable", () => {
    const arr = [1, 2];
    expect(arr).not.toBeImmutable();
  });

  it("is immutable", () => {
    const list = List.of(1, 2);
    expect(list).toBeImmutable();
  })
});

toBeIterableImmutable

Asserts that the data structure is an iterable immutable.

import { List } from "immutable";

declare("Iterable immutable", () => {
  it("is not an iterable immutable", () => {
    const arr = [1, 2];
    expect(arr).not.toBeIterableImmutable();
  });
  
  it("is an iterable immutable", () => {
    const list = List.of(1, 2);
    expect(list).toBeIterableImmutable();
  })
});

toBeKeyedImmutable

Asserts that the data structure is keyed immutable structure.

import { Map, List } from "immutable";

declare("Keyed immutable", () => {
  it("it is not a keyed immutable", () => {
    const list = List.of(1, 2);
    expect(list).not.toBeKeyedImmutable();
  });
  
  it("is a keyed immutable", () => {
    const map = Map({ a: 1 });
    expect(map).toBeKeyedImmutable();
  });
});

toBeIndexedImmutable

Asserts that the data structure is an indexed immutable structure.

import { Map, List } from "immutable";

declare("Indexed Immutable", () => {
  it("is not an indexed immutable", () => {
    const map = Map({ a: 1 });
    expect(map).not.toBeIndexedImmutable();
  }):
  
  it("is an indexed immutable", () => {
    const list = List.of(1, 2);
    expect(list).toBeIndexedImmutable();
  });
});

toBeAssociativeImmutable

Asserts that the data structure is an associative immutable structure.

import { fromJS, Map } from "immutable";

declare("Associtive Immutable", () => {
  it("is not an associative immutable", () => {
    const f = fromJS("not associative");
    expect(f).not.toBeAssociativeImmutable();
  });
  
  it("is an associative immutable", () => {
    const map = Map({ a: 1 });
    expect(m).toBeAssociativeImmutable();
  });
});

toBeOrderedImmutable

Asserts that the data structure is an ordered immutable structure.

import { Map, List, OrderedMap, OrderedSet } from "immutable";

declare("Ordered Immutable", () => {
  it("is not ann ordered immutable", () => {
    const map = Map({ a: 1 });
    expect(map).not.toBeOrderedImmutable();
  });
  
  it("is an ordered immutable", () => {
    const l = List.of(1, 2);
    const o = OrderedMap({ a: 1 }, {b: 2});
    const s = OrderedSet([1, 2]);
    expect(l).toBeOrderedImmutable();
    expect(o).toBeOrderedImmutable();
    expect(s).toBeOrderedImmutable();
  });
});

toBeImmutableList

Asserts that the data structure is an immutable list.

import { List, Map } from "immutable";

declare("Immutable List", () => {
  it("it is not an immutable list", () => {
    const map = Map({ a: 1 });
    expect(m).not.toBeImmutableList();
  });
  
  it("is an immutable list", () => {
    const l1 = List.of(1, 2);
    const l2 = List([1, 2]);
    expect(l1).toBeImmutableList();
    expect(l2).toBeImmutableList();
  });
});

toBeImmutableMap

Asserts that the data structure is an immutable map.

import { List, Map } from "immutable";

declare("Immutable Map", () => {
  it("is not an immutable map", () => {
    const l = List.of(1, 2);
    expect(l).not.toBeImmutableMap();
  });
  
  it("is an immutable map", () => {
    const m = Map({ a: 1 });
    expect(m).toBeImmutableMap();
  });
});

toBeImmutableOrderedMap

Asserts that the data structure is an immutable ordered map.

import { Map, OrderedMap } from "immutable";

declare("Immutable Ordered Map", () => {
  it("is not an ordered immutable map", () => {
    const m = Map({ a: 1 });
    expect(m).not.toBeImmutableOrderedMap();
  });
  
  it("is an immutable map", () => {
    const o = OrdereMap({ a: 1 }, { b: 2 });
    expect(o).toBeImmutableOrderedMap();
  });
});

toBeImmutableOrderedSet

Asserts that the data structure is an immutable ordered set.

import { OrderedSet, Map } from "immutable";

declare("Immutable Oredered Set", () => {
  it("is not an ordered immutable set", () => {
    const m = Map({a: 1});
    expect(m).not.toBeImmutableOrderedSet();
  });
  
  it("is an ordered immutable set", () => {
    const s = OrderedSet([1, 2]);
    expect(s).toBeImmutableOrderedSet();
  });
});

toBeImmutableSet

Asserts that the data structure is an immutable set.

import { Set, Map } from "immutable";

declare("Immutable Set", () => {
  it("is not an immutable set", () => {
    const m = Map({ a: 1 });
    expect(m).not.toBeImmutableSet();
  });
  
  it("is an immutable set", () => {
    const s = Set([1, 2]);
    expect(s).toBeImmutableSet();
  });
});

toBeImmutableStack

Asserts that the data structure is an immutable stack.

improt { Stack } from "immutable";

declare("Immutable Stack", () => {
  it("is not an immutable stack", () => {
    const a = [1, 2];
    expect(a).not.toBeImmutableStack();
  });
  
  it("is an immutable stack", () => {
    const s = Stack([1, 2]);
    expect(s).toBeImmutableStack();
  });
});

toBeImmutableSeq

Asserts that the structure is an immutable sequence.

import { Seq } from "immutable";

declare("Immutable Sequence", () => {
  it("is not an immutable sequence", () => {
    const a = [1, 2];
    expect(a).not.toBeImmutableSeq();
  });
  
  it("is an immutable sequence", () => {
    const s = Seq([1, 2]);
    expect(s).toBeImmutableSeq();
  });
});

toEqualImmutable

Asserts that the input immutable argument is equal to expected immutable input.

import { Map, List } from "immutable";

declare("Equal another Immutable", () => {
  it("does not equal another immutable list", () => {
    const l1 = List.of(1, 2);
    const l2 = List.of(1, 2, 3);
    expect(l1).not.toBe(l2);
    expect(l1).not.toEqualImmutable(l2);
  });
  
  it("is equal to another immutable list", () => {
    const l1 = List.of(1, 2);
    const l2 = List.of(1, 2);
    expect(l1).not.toBe(l2);
    expect(l1).toEqualImmutable(l2);
  });
  
  it("does not equal another immutable map", () => {
    const m1 = Map({ a: 1 });
    const m2 = Map({ b: 2 })
    expect(m1).not.toBe(m2);
    expect(m1).not.toEqualImmutable();
  });
  
  it("is equal to another immutable map", () => {
    const m1 = Map({ a: 1 });
    const m2 = Map({ a: 1 });
    expect(m1).not.toBe(m2);
    expect(m1).toEqualImmutable();
  });
});
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.20-alpha

6 years ago

0.0.19-alpha

6 years ago

0.0.18-alpha

6 years ago

0.0.17-alpha

6 years ago

0.0.16-alpha

6 years ago

0.0.15-alpha

6 years ago

0.0.14-alpha

6 years ago

0.0.13-alpha

6 years ago

0.0.12-alpha

6 years ago

0.0.11-alpha

6 years ago

0.0.10-alpha

6 years ago

0.0.9-alpha

6 years ago

0.0.8-alpha

6 years ago

0.0.7-alpha

6 years ago

0.0.6-alpha

6 years ago

0.0.5-alpha

6 years ago

0.0.4-alpha

6 years ago

0.0.3-alpha

6 years ago

0.0.2-alpha

6 years ago

0.0.1-alpha

6 years ago

0.0.0-alpha

6 years ago