1.5.1-alpha.6 • Published 3 years ago

pwajet-test-utils v1.5.1-alpha.6

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

PWAjet test utils

What is it?

This library designed to help you write unit tests for your PWAjet extension.

pwajet is not available as a library or module: it available only in browser environment at runtime. So you should mock your imports from pwajet.core manually.

With this library you shouldn`t

Getting started

yarn add pwajet-test-utils -D

Add this to your jest setup file:

// Do it first to allow pwajet to init successfully
(global as any).pwajet = {
  esmExtensions: []
}

// import utils
import pwajet from 'pwajet-test-utils'

// mock pwajet with utils
jest.mock(
  'pwajet',
  () => ({
    core: pwajet.core,
  }),
  { virtual: true }
)

What is a setup file?

If your extension is based on pwajet-extension example, you need this file https://github.com/simtechdev/pwajet-extension/blob/master/src/setupTests.ts

else read the docs https://jestjs.io/docs/configuration#setupfiles-array