Module test file
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.
Example
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.
Additional resources
Atsauksmes
https://aka.ms/ContentUserFeedback.
Drīzumā: 2024. gada laikā mēs pakāpeniski pārtrauksim izmantot “GitHub problēmas” kā atsauksmju par saturu mehānismu un aizstāsim to ar jaunu atsauksmju sistēmu. Papildinformāciju skatiet:Iesniegt un skatīt atsauksmes par