piumino
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

Piumino

Piumino, meaning duvet in Italian, is like a duvet over the bed called Angular TestBed. It provides test helpers to test trivial things like inputs and outputs with a single line.

Requirements

  • Tests that use Angular TestBed (either directly or under the hood, so long as a fixture is available)
  • Jest or Jasmine (other frameworks will likely work as well but are untested)

Installation

npm i -D piumino

Usage

Import Piumino into the test file and construct it.

import { Piumino } from "piumino";

const piumino = new Piumino();

Then init it with the fixture from TestBed.

piumino.init(fixture);

Tests can then be executed in two ways.
Selector is a CSS selector for the element to expect something on or the HTMLElement itself.

As a one-liner.

it(...piumino.expect("selector").xxx.build());

In an existing test.

it("Existing test", () => {
    piumino.expect("selector").xxx.execute();
});

API

.not

Invert the result of the matchers.

.toHaveText()

Expect the selected element to have the provided text.

piumino.expect("selector").toHaveText("text")

.toHaveTextCaseInsensitive()

Expect the selected element to have the provided text, ignoring case.

piumino.expect("selector").toHaveTextCaseInsensitive("text")

.toBePresent()

Expect the selected element to be present in the DOM.

piumino.expect("selector").toBePresent()

.toBeVisible()

Expect the selected element to be visible in the DOM.

piumino.expect("selector").toBeVisible()

.input()

Select an input of the selected element to expect something on.

piumino.expect("selector").input("input")

.not

Invert the result of the matchers.

.toEqual()

Expect the input of the selected element to equal the provided value.

<element input="value"/>
piumino.expect("selector").input("input").toEqual("value")

.toBeBoundTo()

Expect the input of the selected element to be bound to the provided property of the fixture's component.
NOTE: Does not work for getters.

<element [input]="property"/>
piumino.expect("selector").input("input").toBeBoundTo("property")
.modifyWith()

Expect the bounded property to be modified with the provided value.

<element [input]="property"/>
piumino.expect("selector").input("input").toBeBoundTo("property").modifyWith("value")

.toCall()

Expect the input of the selected element to call the provided function of the fixture's component. Also checks if the return value of the function is assigned to the input.

<element [input]="func()"/>
piumino.expect("selector").input("input").toCall("func")
.with()

Expect the called function to be called with the provided values.

<element [input]="func(value)"/>
piumino.expect("selector").input("input").toCall("func").with("value")

.output()

Select an output of the selected element to expect something on.

piumino.expect("selector").output("output")

.not

Invert the result of the matchers.

.toBeBoundTo()

Expect the output of the selected element to be bound to the provided property of the fixture's component.
NOTE: Does not work for setters if there is no getter.

<element (output)="property = $event"/>
piumino.expect("selector").output("output").toBeBoundTo("property")
.modifyWith()

Expect the bounded property to be modified with the provided value.

<element (output)="property = $event"/>
<element (output)="property = value"/>
piumino.expect("selector").output("output").toBeBoundTo("property").modifyWith("value")

.toCall()

Expect the output of the selected element to call the provided function of the fixture's component.

<element (output)="func()"/>
piumino.expect("selector").output("output").toCall("func")
.with()

Expect the called function to be called with the provided values. The last of the provided values is dispatched as $event.

<element (output)="func($event)"/>
<element (output)="func(value, $event)"/>
piumino.expect("selector").output("output").toCall("func").with("value")

TODO

  • Add .toCallThrough() to input/output matcher
  • Make .toBeBoundTo() in input matcher work with getters
  • Make .toBeBoundTo() in output matcher work with setters without a getter

Package Sidebar

Install

npm i piumino

Weekly Downloads

5

Version

2.2.0

License

ISC

Unpacked Size

42.1 kB

Total Files

25

Last publish

Collaborators

  • luukrijnbende