Mocking library to help with testing PowerApps Component Framework Components
npm install @shko.online/componentframework-mock* Examples will reference the OwnerLookup control in this repository.
npm
cmd
npm install -D @shko.online/componentframework-mock
`
yarn
`cmd
yarn add -D @shko.online/componentframework-mock
`
In your test or story you should import your component and IInputs, IOutputs. ex:
`typescript
import { OwnerLookup } from '../__sample-components__/OwnerLookup';
import { IInputs, IOutputs } from '../__sample-components__/OwnerLookup/generated/ManifestTypes';
`
Also you should import ComponentFrameworkMockGenerator or ComponentFrameworkMockGeneratorReact and the necessary property mocks.
`typescript
import { ComponentFrameworkMockGenerator, LookupPropertyMock } from '@shko.online/componentframework-mock';
`
The first parameter to the generator is your component, and the second parameter is the mapping between your component parameters and the propery mock. The third parameter is required only for ComponentFrameworkMockGenerator, because the virtual components return a ReactElement and don't use the container element. You should create an instance of the generator in your code like this:
`typescript
let mockGenerator: ComponentFrameworkMockGenerator = new ComponentFrameworkMockGenerator(
OwnerLookup,
{
value: LookupPropertyMock,
},
container,
);
`
You can initialize/bind the state of the in-memory database using the following method:
`typescript
mockGenerator.context._SetCanvasItems({
value: {
entityType: 'team',
id: 'guid1',
name: 'Shko Online',
},
});
`
You should call excatly once ExecuteInit and at least once ExecuteUpdate which control the system updates:
`typescript
mockGenerator.ExecuteInit();
mockGenerator.ExecuteUpdateView();
`
* Check our sample tests in the \_\_tests\_\_/Components folder for more details and inspiration.
* Check our sample stories in the Storybook/stories folder for more details and inspiration.
* Also check https://github.com/Shko-Online/ComponentFramework-Mock-Tests and https://github.com/Shko-Online/ComponentFramework-Mock-React-Tests for tests and stories written against PowerApps samples and PowerCAT code components.
UPDATE 2022-12-17!
We are changing the license of this library from RPL-1.5 to MIT` to boost adoption. The owners of the license are Betim Beja and Shko Online LLC. If you want to help with the development of this library and all the other Open Source products by Betim Beja (under the brand AlbanianXrm) and Shko Online LLC you can buy consulting services by contacting us at sales@shko.online