title | description | author | ms.date | ms.topic | audience | ms.reviewer | ms.search.region | ms.author | ms.search.validFrom | ms.dyn365.ops.version | ms.custom | ms.assetid |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Module test file |
This article covers the module test file in Microsoft Dynamics 365 Commerce. |
samjarawan |
01/31/2020 |
article |
Developer |
v-chgriffin |
Global |
samjar |
2019-10-31 |
Release 10.0.5 |
[!include banner]
This article covers the module test file in Microsoft Dynamics 365 Commerce.
The module test file is used for local unit testing. It contains the mock data that is required to run the tests.
The following example shows a default test file that is created for a new module.
import { buildMockModuleProps} from '@msdyn365-commerce/core';
/// <reference types="jest" />
// tslint:disable-next-line:no-unused-variable
import * as React from 'react';
import * as renderer from 'react-test-renderer';
import ProductFeature from '../productFeature';
import { IProductFeatureData } from '../productFeature.data';
import {
IProductFeatureConfig,
IProductFeatureProps
} from '../productFeature.props.autogenerated';
const mockData: IProductFeatureData = {
actionResponse: {
text: 'Sample Response Data'
}
};
const mockConfig: IProductFeatureConfig = {
showText: 'productFeature'
};
const mockActions = {};
describe('ProductFeature', () => {
let moduleProps: IProductFeatureProps<IProductFeatureData>;
beforeAll(() => {
moduleProps = buildMockModuleProps(mockData, mockActions, mockConfig) as IProductFeatureProps<IProductFeatureData>;
});
it('renders correctly', () => {
const component: renderer.ReactTestRenderer = renderer.create(
<ProductFeature {...moduleProps} />
);
const tree: renderer.ReactTestRendererJSON | null = component.toJSON();
expect(tree).toMatchSnapshot();
});
});
Note that the mock data fields are set inside this file.
Module props.autogenerated.ts file
[!INCLUDEfooter-include]