1.0.11 • Published 2 months ago

@universal-packages/dynamic-api-jest v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Dynamic Api Jest

npm version Testing codecov

Jest matchers for Dynamic Api testing.

Install

npm install @universal-packages/dynamic-api-jest

npm install @universal-packages/dynamic-api

Setup

Add the following to your jest.config.js or where you configure Jest:

module.exports = {
  setupFilesAfterEnv: ['@universal-packages/dynamic-api-jest']
}

Matchers

toHaveBeenPerformed

import { MyDynamic } from './MyDynamic'

it('should have performed MyDynamic', async () => {
  await dynamicApi.perform('my-dynamic')

  expect(MyDynamic).toHaveBeenPerformed()
})

toHaveBeenPerformedWith

import { MyDynamic } from './MyDynamic'

it('should have performed MyDynamic with payload', async () => {
  await dynamicApi.perform('my-dynamic', { foo: 'bar' })

  expect(MyDynamic).toHaveBeenPerformedWith({ foo: 'bar' })
})

toHaveBeenHookedBefore

import { MyDynamic } from './MyDynamic'
import { MyHook } from './MyHook'

it('should have hooked MyHook before MyDynamic', async () => {
  await dynamicApi.perform('my-dynamic')

  expect(MyHook).toHaveBeenHookedBefore(MyDynamic)
})

toHaveBeenHookedAfter

import { MyDynamic } from './MyDynamic'
import { MyHook } from './MyHook'

it('should have hooked MyHook after MyDynamic', async () => {
  await dynamicApi.perform('my-dynamic')

  expect(MyHook).toHaveBeenHookedAfter(MyDynamic)
})

Typescript

In order for typescript to see the global types you need to reference the types somewhere in your project, normally ./src/globals.d.ts.

/// <reference types="@universal-packages/dynamic-api-jest" />

This library is developed in TypeScript and shipped fully typed.

Contributing

The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.

License

MIT licensed.

1.0.11

2 months ago

1.0.10

2 months ago

1.0.9

2 months ago

1.0.8

3 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.0

11 months ago