1.4.0 • Published 6 months ago

@tepez/jasmine-misc-matchers v1.4.0

Weekly downloads
7
License
MIT
Repository
github
Last release
6 months ago

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

1.4.0

6 months ago

1.3.0

12 months ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.13

3 years ago

0.4.12

3 years ago

0.4.11

3 years ago

0.4.10

4 years ago

0.4.9

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.0

6 years ago