1.0.1 • Published 5 years ago

@randonneur/tapering v1.0.1

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

@randonneur/tapering npm version

A thin tape wrapper with minimalistic API surface.

Installation

npm install @randonneur/tapering

API

This Node.js module exports an object with three methods:

  • test
  • suite
  • their external tape dependency

The test and suite signatures can be concisely described with TypeScript syntax:

interface Assertion {
  actual: any;
  expected: any;
}

interface Suite {
  [expectation: string]: Assertion;
}

declare function test(expectation: string, assertion: Assertion): void;

declare function suite(moduleUnderTest: string, dictionary: Suite): void;

Assertion property overload semantics:

If expected is a primitive, the assertion method is equal, otherwise deepEqual.

If actual is a method, its return value is used. If its return value is a Promise, its resolved value is awaited.

NB: To verify the identity of an object, simply let actual be a method that returns a strict equality expression and expected a boolean.

Example

const { test, suite, tape } = require('@randonneur/tapering);

test('The module under test knows the answer to primitive questions', {
  actual: 42,
  expected: 42,
});

suite('The module under test', {
  'knows the answer to primitive questions': {
    actual: 42,
    expected: 42,
  },
  'knows the answer to complex questions': {
    actual: { answer: 42 },
    expected: { answer: 42 },
  },
  'knows the answer to verbose questions': {
    actual() {
      const { PI, sign } = Math;
      const a = -~PI;
      const b = sign(a) * 2;
    
      return [a, b].join('');
    },
    expected: 42,
  },
  'knows the answer to async questions': {
    actual() {
      return new Promise(resolve => {
        setTimeout(() => {
          resolve(42);
        }, 1000);          
      });
    },
    expected: 42,
  },
  'knows the answer to cases of mistaken identity': {
    actual() {
      const a = { answer: 42 };
      const b = a;
    
      return a !== b;
    },
    expected: false,
  },
});

tape('Some plain old tape test', ({ end, equal }) => {
  equal(void 0, undefined);
  end();
});

See also

https://en.wikipedia.org/wiki/Tapering

License

MIT

1.0.1

5 years ago

1.0.0

5 years ago