パッケージの詳細

beater-matcher

bouzuya11MIT0.2.0

A matcher library for beater.

beater, bouzuya, matcher, test

readme

beater-matcher

A matcher library for beater.

Installation

$ npm install --save-dev beater-matcher

Usage

import assert from 'assert';
import {
  any,
  anyArray,
  anyNumber,
  anyString,
  anyObject,
  match,
  matchString,
  partialObject,
} from 'beater-matcher';

const value = {
  a: 123,
  b: 'abc',
  c: [1, 2, 3],
  d: { a: 1, b: 2, c: 3 }
};

// (basic matchers)
// value as matcher
assert(match(value, value));

// (pre-defined matchers)
// any matcher
assert(match(value, any()));

// anyXXX matcher
assert(match(
  value,
  {
    a: anyNumber(),
    b: anyString(),
    c: anyArray(),
    d: anyObject()
  }
));

// partialObject and matchString matcher
assert(match(value, partialObject({ b: matchString(/^ab/) })));

// (custom matcher)
const abcMatcher = defineMatcher(
  (value: unknown): boolean => {
    return typeof value === 'string' && value.startsWith('ABC');
  }
);
assert(match('ABCDEF', abcMatcher));

Badges

npm version Travis CI

License

MIT

Author

bouzuya <m@bouzuya.net> (https://bouzuya.net/)

更新履歴

0.2.0 (2020-02-08)

  • build!: drop support for node.js v8 (444fe9c)
  • Bump @babel/cli from 7.8.3 to 7.8.4 (7a0b7a5)
  • Bump @babel/core from 7.8.3 to 7.8.4 (05c416c)
  • Bump @babel/preset-env from 7.8.3 to 7.8.4 (c09cb56)
  • Bump rimraf from 3.0.0 to 3.0.1 (be32eae)
  • Bump typescript from 3.7.4 to 3.7.5 (312a317)
  • style: apply prettier (2640d5b)
  • build: add automerge settings for @babel/* (24190c5)
  • build: add automerged_updates to dependabot config (1c0ca48)
  • build: add eslint and prettier (aabf10d)
  • build: ignore @types/node@13.x (1567a5f)
  • build(deps-dev): bump @types/node from 10.17.13 to 10.17.14 (1caa64d)
  • build(deps-dev): update beater (81cb52c)

BREAKING CHANGE

  • drop support for node.js v8

0.1.1 (2020-01-16)

  • build: bump babel to 7.8.3 (28ac2d2)
  • build: bump beater to 8.0.2 (ca0aa39)