@tepez/jasmine-misc-matchers
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

jasmine-misc-matchers

Various matchers for jasmine2

npm version

Install

npm install --save @tepez/jasmine-misc-matchers

Usage

const { matchers, JSONStringMatcher } = require('@tepez/jasmine-misc-matchers');

beforeEach(() => {
    jasmine.addMatchers(matchers);
});

it('toHaveBeenCalledWithAt', () => {
    const spy = jasmine.createSpy('mock spy');
    spy(1, 2, 3);
    expect(spy).toHaveBeenCalledWithAt(0, [1, 2, 3]);
});

it('JSONStringMatcher', () => {
    expect('{"a": "b"}').toEqual(JSONStringMatcher({a: 'b'}));
});

API

Custom matchers

Spies

Both jasmine and sinon spies are supported.

  • expect(spy: jasmine.Spy).toHaveBeenCalledWithAt(callIndex: number, expectedArgs: any[])

Expects the call arguments of the callIndex call to a spied-on function to equal exactly expectedArgs.

  • expect(spy: jasmine.Spy).toHaveBeenCalledWithAt(callIndex: number, expectedArgs: any[])

Expects the spy to have been called exactly

Misc

  • toHaveOwnProperties
  • toHaveExactKeys

Custom asymmetric equality tester

  • JSONStringMatcher(obj)

Tests weather a string is a JSON serialization of given obj.

Utilities

  • setSpecTimeout(timeout: number): void
  • mockClock(date: Date): void
  • updateDate(date: Date): void
  • getJsonRep(obj: any): any

Nodejs specific utilities

  • toEqualHtml

Compares html using html-differ.

Node.js only by default because html-differ needs some mocking to run on the browser.

See src/browser-chalk.js for details.

  • htmlTextMatcher

Compares HTML to text using html-to-text

  • executeSpecFile(filePath: string): Promise<jasmine.CustomReporterResult[]>

Execute the specs a jasmine specs file at given path and return the spec results. Very useful for testing failures of custom matchers.

  • setLongTimeoutOnDebug()

Set very long timeout if running the specs in debug.

  • isDebug()

Return true if running in debug mode.

  • backupAndRestoreEnv()

Copy process.env before each spec and restore it after it

  • JasmineMemoryUsageReporter

Custom reporter for logging the memory usage before/after every spec to a CSV file

Readme

Keywords

none

Package Sidebar

Install

npm i @tepez/jasmine-misc-matchers

Weekly Downloads

2

Version

1.4.0

License

MIT

Unpacked Size

163 kB

Total Files

32

Last publish

Collaborators

  • tomyam1