This test suite is a configuration for Shopgate's React projects.
The unit test suite needs React to be installed in at least version ~16.2.0
This configuration uses Jest for running the tests. It is only an extension of the default Jest configuration and prepares your tests for any React PWA using the Shopgate Cloud.
To install and use this package, you need to run the following command in your project's root directory:
npm install @shopgate/pwa-unit-test --save-dev
All test files should follow the naming convention of *spec.(js|jsx)
.
You have two options of how to create a configuration for Jest:
- You can create your own configuration following the Jest Documentation
- You can use Shopgate's pre-defined configuration and extend it as you wish.
NOTE: Using and extending the Shopgate configuration is the preferred way!
Create a file called jest.config.js
in the root of your project.
Add the following line to it:
module.exports = require('@shopgate/pwa-unit-test/jest.config');
Create a file called jest.config.js
in the root of your project.
Add the following line in the beginning of the file:
const defaultConfig = require('@shopgate/pwa-unit-test/jest.config');
This will load the default configuration. Now you can extend it by spreading the defaultConfig
into a newly created configuration object:
module.exports = {
...defaultConfig,
[Your config goes here],
};
Here is an example showing how to extend the default configuration:
const defaultConfig = require('@shopgate/pwa-unit-test/jest.config');
module.exports = {
...defaultConfig,
moduleNameMapper: {
'^Components(.*)$': '<rootDir>/components',
'^Styles(.*)$': '<rootDir>/styles',
},
};
Shopgate is the leading mobile commerce platform.
Shopgate offers everything online retailers need to be successful in mobile. Our leading software-as-a-service (SaaS) enables online stores to easily create, maintain and optimize native apps and mobile websites for the iPhone, iPad, Android smartphones and tablets.
Unit test setup for the Shopgate Connect PWA is available under the Apache License, Version 2.0.
See the LICENSE.md file for more information.