JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 242
  • Score
    100M100P100Q82725F
  • License MIT

Write Beautiful Specs with Custom Matchers for Jasmine

Package Exports

  • expect-more-jasmine

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (expect-more-jasmine) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

expect-more-jasmine

Write Beautiful Specs with Custom Matchers for Jasmine

NPM version NPM downloads Build Status Maintainability Follow JamieMason on GitHub Follow fold_left on Twitter

Table of Contents

Overview

expect-more-jasmine is a huge library of test matchers for a range of common use-cases, to make tests easier to read and produce relevant and useful messages when they fail.

Avoid vague messages such as "expected false to be true" in favour of useful cues like "expected 3 to be even number", and avoid implementation noise such as expect(paws.length % 2 === 0).toEqual(true) in favour of simply stating that you expect(paws.length).toBeEvenNumber().

🌩 Installation

npm install expect-more-jasmine --save-dev

🕹 Configuration

import 'expect-more-jasmine' or require('expect-more-jasmine') at the top your test file.

🔬 Matchers

toBeAfter
expect(new Date('2020-01-01')).toBeAfter(new Date('2019-12-31'));
toBeArrayOfBooleans
expect([true, false, new Boolean(true)]).toBeArrayOfBooleans();
toBeArrayOfNumbers
expect([12, 0, 14]).toBeArrayOfNumbers();
toBeArrayOfObjects
expect([{}, new Object()]).toBeArrayOfObjects();
toBeArrayOfSize
expect(['i', 'contain', 4, 'items']).toBeArrayOfSize(4);
toBeArrayOfStrings
expect(['we', 'are', 'all', 'strings']).toBeArrayOfStrings();
toBeArray
expect([2, true, 'string']).toBeArray();
toBeAsyncFunction
expect(async () => {
  await fetch('...');
}).toBeAsyncFunction();
toBeBefore
expect(new Date('2019-12-31')).toBeBefore(new Date('2020-01-01'));
toBeBoolean
expect(false).toBeBoolean();
toBeCalculable
expect('100').toBeCalculable();
toBeDate
expect(new Date('2019-12-31')).toBeDate();
toBeDecimalNumber
expect(12.55).toBeDecimalNumber();
toBeDivisibleBy
expect(12).toBeDivisibleBy(2);
toBeEmptyArray
expect([]).toBeEmptyArray();
toBeEmptyObject
expect({}).toBeEmptyObject();
toBeEmptyString
expect('').toBeEmptyString();
toBeEvenNumber
expect(2).toBeEvenNumber();
toBeFalse
expect(false).toBeFalse();
toBeFunction
expect(() => 'i am a function').toBeFunction();
toBeGeneratorFunction
expect(function* gen() {
  yield 'i am a generator';
}).toBeGeneratorFunction();
toBeIso8601
expect('1999-12-31T23:59:59').toBeIso8601();
toBeJsonString
expect('{"i":"am valid JSON"}').toBeJsonString();
toBeLongerThan
expect(['i', 'have', 3]).toBeLongerThan([2, 'items']);
toBeNonEmptyArray
expect(['i', 'am not empty']).toBeNonEmptyArray();
toBeNonEmptyObject
expect({ i: 'am not empty' }).toBeNonEmptyObject();
toBeNonEmptyString
expect('i am not empty').toBeNonEmptyString();
toBeNumber
expect(8).toBeNumber();
toBeObject
expect({}).toBeObject();
toBeOddNumber
expect(5).toBeOddNumber();
toBeRegExp
expect(new RegExp('i am a regular expression')).toBeRegExp();
toBeSameLengthAs
expect(['i also have', '2 items']).toBeSameLengthAs(['i have', '2 items']);
toBeShorterThan
expect(['i have one item']).toBeShorterThan(['i', 'have', 4, 'items']);
toBeString
expect('i am a string').toBeString();
toBeTrue
expect(true).toBeTrue();
toBeValidDate
expect(new Date('2020-01-01')).toBeValidDate();
toBeWalkable
expect({}).toBeWalkable();
toBeWhitespace
expect(' ').toBeWhitespace();
toBeWholeNumber
expect(8).toBeWholeNumber();
toBeWithinRange
expect(7).toBeWithinRange(0, 10);
toEndWith
expect('JavaScript').toEndWith('Script');
toHaveArrayOfBooleans
expect({ child: { grandchild: [true, false, new Boolean(true)] } }).toHaveArrayOfBooleans(
  'child.grandchild',
);
toHaveArrayOfNumbers
expect({ child: { grandchild: [12, 0, 14] } }).toHaveArrayOfNumbers('child.grandchild');
toHaveArrayOfObjects
expect({ child: { grandchild: [{}, new Object()] } }).toHaveArrayOfObjects('child.grandchild');
toHaveArrayOfSize
expect({ child: { grandchild: ['i', 'contain', 4, 'items'] } }).toHaveArrayOfSize(
  'child.grandchild',
  4,
);
toHaveArrayOfStrings
expect({ child: { grandchild: ['we', 'are', 'all', 'strings'] } }).toHaveArrayOfStrings(
  'child.grandchild',
);
toHaveArray
expect({ child: { grandchild: [2, true, 'string'] } }).toHaveArray('child.grandchild');
toHaveAsyncFunction
expect({
  child: {
    grandchild: async () => {
      await fetch('...');
    },
  },
}).toHaveAsyncFunction('child.grandchild');
toHaveBoolean
expect({ child: { grandchild: false } }).toHaveBoolean('child.grandchild');
toHaveCalculable
expect({ child: { grandchild: '100' } }).toHaveCalculable('child.grandchild');
toHaveDateAfter
expect({ child: { grandchild: new Date('2020-01-01') } }).toHaveDateAfter(
  'child.grandchild',
  new Date('2019-12-31'),
);
toHaveDateBefore
expect({ child: { grandchild: new Date('2019-12-31') } }).toHaveDateBefore(
  'child.grandchild',
  new Date('2020-01-01'),
);
toHaveDate
expect({ child: { grandchild: new Date('2019-12-31') } }).toHaveDate('child.grandchild');
toHaveDecimalNumber
expect({ child: { grandchild: 12.55 } }).toHaveDecimalNumber('child.grandchild');
toHaveDivisibleBy
expect({ child: { grandchild: 12 } }).toHaveDivisibleBy('child.grandchild', 2);
toHaveEmptyArray
expect({ child: { grandchild: [] } }).toHaveEmptyArray('child.grandchild');
toHaveEmptyObject
expect({ child: { grandchild: {} } }).toHaveEmptyObject('child.grandchild');
toHaveEmptyString
expect({ child: { grandchild: '' } }).toHaveEmptyString('child.grandchild');
toHaveEndingWith
expect({ child: { grandchild: 'JavaScript' } }).toHaveEndingWith('child.grandchild', 'Script');
toHaveEvenNumber
expect({ child: { grandchild: 2 } }).toHaveEvenNumber('child.grandchild');
toHaveFalse
expect({ child: { grandchild: false } }).toHaveFalse('child.grandchild');
toHaveGeneratorFunction
expect({
  child: {
    grandchild: function* gen() {
      yield 'i am a generator';
    },
  },
}).toHaveGeneratorFunction('child.grandchild');
toHaveGreaterThanOrEqualTo
expect({ child: { grandchild: 10 } }).toHaveGreaterThanOrEqualTo('child.grandchild', 5);
toHaveIso8601
expect({ child: { grandchild: '1999-12-31T23:59:59' } }).toHaveIso8601('child.grandchild');
toHaveJsonString
expect({ child: { grandchild: '{"i":"am valid JSON"}' } }).toHaveJsonString('child.grandchild');
toHaveLessThanOrEqualTo
expect({ child: { grandchild: 8 } }).toHaveLessThanOrEqualTo('child.grandchild', 12);
toHaveLongerThan
expect({ child: { grandchild: ['i', 'have', 3] } }).toHaveLongerThan('child.grandchild', [
  2,
  'items',
]);
toHaveMethod
expect({ child: { grandchild: () => 'i am a function' } }).toHaveMethod('child.grandchild');
toHaveNonEmptyArray
expect({ child: { grandchild: ['i', 'am not empty'] } }).toHaveNonEmptyArray('child.grandchild');
toHaveNonEmptyObject
expect({ child: { grandchild: { i: 'am not empty' } } }).toHaveNonEmptyObject('child.grandchild');
toHaveNonEmptyString
expect({ child: { grandchild: 'i am not empty' } }).toHaveNonEmptyString('child.grandchild');
toHaveNull
expect({ child: { grandchild: null } }).toHaveNull('child.grandchild');
toHaveNumberNear
expect({ child: { grandchild: 4.8 } }).toHaveNumberNear('child.grandchild', 5, 0.5);
toHaveNumberWithinRange
expect({ child: { grandchild: 7 } }).toHaveNumberWithinRange('child.grandchild', 0, 10);
toHaveNumber
expect({ child: { grandchild: 8 } }).toHaveNumber('child.grandchild');
toHaveObject
expect({ child: { grandchild: {} } }).toHaveObject('child.grandchild');
toHaveOddNumber
expect({ child: { grandchild: 5 } }).toHaveOddNumber('child.grandchild');
toHaveRegExp
expect({ child: { grandchild: new RegExp('i am a regular expression') } }).toHaveRegExp(
  'child.grandchild',
);
toHaveSameLengthAs
expect({ child: { grandchild: ['i also have', '2 items'] } }).toHaveSameLengthAs(
  'child.grandchild',
  ['i have', '2 items'],
);
toHaveShorterThan
expect({ child: { grandchild: ['i have one item'] } }).toHaveShorterThan('child.grandchild', [
  'i',
  'have',
  4,
  'items',
]);
toHaveStartingWith
expect({ child: { grandchild: 'JavaScript' } }).toHaveStartingWith('child.grandchild', 'Java');
toHaveString
expect({ child: { grandchild: 'i am a string' } }).toHaveString('child.grandchild');
toHaveTrue
expect({ child: { grandchild: true } }).toHaveTrue('child.grandchild');
toHaveUndefined
expect({ child: { grandchild: undefined } }).toHaveUndefined('child.grandchild');
toHaveValidDate
expect({ child: { grandchild: new Date('2020-01-01') } }).toHaveValidDate('child.grandchild');
toHaveWalkable
expect({ child: { grandchild: {} } }).toHaveWalkable('child.grandchild');
toHaveWhitespace
expect({ child: { grandchild: ' ' } }).toHaveWhitespace('child.grandchild');
toHaveWholeNumber
expect({ child: { grandchild: 8 } }).toHaveWholeNumber('child.grandchild');
toStartWith
expect('JavaScript').toStartWith('Java');

🙋🏽‍♂️ Getting Help

Get help with issues by creating a Bug Report or discuss ideas by opening a Feature Request.

👀 Other Projects

If you find my Open Source projects useful, please share them ❤️

🤓 Author

I'm Jamie Mason from Leeds in England, I began Web Design and Development in 1999 and have been Contracting and offering Consultancy as Fold Left Ltd since 2012. Who I've worked with includes Sky Sports, Sky Bet, Sky Poker, The Premier League, William Hill, Shell, Betfair, and Football Clubs including Leeds United, Spurs, West Ham, Arsenal, and more.

Follow JamieMason on GitHub Follow fold_left on Twitter