Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@shko.online/componentframework-mock

shko-online207MIT0.8.1TypeScript support: included

Mocking library to help with testing PowerApps Component Framework Components

componentframework, d365, pcf, mock, made-in-albania

readme

ComponentFramework Mock NPM Downloads

This library mocks the entire ComponentFramework library and enables users to write tests and stories for their PCF components.

Explore the endless possibilities in the following Storybook https://main--64b05f276a7d4d8ef73a9dd8.chromatic.com/ ComponentFramework-Mock Storybook

Quick Start

First step is to add our package as a development dependency on your project.

* Examples will reference the OwnerLookup control in this repository.

npm

npm install -D @shko.online/componentframework-mock

yarn

yarn add -D @shko.online/componentframework-mock

In your test or story you should import your component and IInputs, IOutputs. ex:

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.

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:

let mockGenerator: ComponentFrameworkMockGenerator<IInputs, IOutputs> = new ComponentFrameworkMockGenerator(
    OwnerLookup,
    {
        value: LookupPropertyMock,
    },
    container,
);

You can initialize/bind the state of the in-memory database using the following method:

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:

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

Contributing

Contributions are welcome. Before contributing please check that you don't violate any IP, and consider that your contribution will be public, but you would be transfering ownership of the code to us.

Code of Conduct

We welcome friendly contributors. Being a library that improves a Microsoft product, we have chosen to follow the Microsoft Open Source Code of Conduct.

changelog

0.8.1 (2025-04-23)

Bug Fixes

  • Generic property is typed properly (5f0f0e5)

0.8.0 (2025-03-31)

Features

  • add support for PropertyMock (multiple types) (2bc20c2)

0.7.1 (2025-03-31)

Bug Fixes

  • specify default type for different property mocks (7abe891)

0.7.0 (2025-03-30)

Features

  • added mock for context.utils.loadDependency (a779d6f)

0.6.5 (2025-03-12)

Bug Fixes

  • properly handling formatDecimal precision (13a04b9)

0.6.4 (2024-11-21)

Bug Fixes

0.6.3 (2024-05-10)

Bug Fixes

  • return primaryIdAttribute on webapi retrieve (95da7f2)

0.6.2 (2024-04-30)

Bug Fixes

  • added more table metadata (5f97640)

0.6.1 (2024-04-27)

Bug Fixes

  • fixed minor typings issues (e1625e9)

0.6.0 (2024-04-12)

Features

0.5.0 (2024-01-18)

Bug Fixes

  • Multiple Components sharing the same properties (6699727)

Features

  • ComponentFrameworkMockOrchestrator (cfa9e9f)
  • Exposed shared db on Orchestrator (8dae1de)
  • OrchestratorInput type (e05a062)

0.4.2 (2024-01-14)

Bug Fixes

  • Correctly set PrimaryImageAttribute (92bdbb6)

0.4.1 (2023-12-29)

Bug Fixes

  • properly managed metadata for number properties (f9d07a3)

0.4.0 (2023-12-27)

Bug Fixes

  • added FluentDesignStateMock (b166807)

Features

0.3.1-beta.1 (2023-12-22)

Bug Fixes

  • added FluentDesignStateMock (b166807)

0.3.0 (2023-12-19)

Bug Fixes

  • retrieve multiple by savedquery and userquery (51103b7)
  • simple retrieve multiple with fetchXml (a7b9ef6)

Features

  • improved retrieveMultiple (2b7bd6e)
  • raising onOutputChanged even if outputs don't change (49cac5d)

0.2.1-beta.1 (2023-12-11)

Bug Fixes

  • retrieve multiple by savedquery and userquery (51103b7)
  • simple retrieve multiple with fetchXml (a7b9ef6)

0.2.0 (2023-12-08)

Bug Fixes

  • improved get attribute metadata and booleanattribute (847c97e)
  • improved metadata for optionsets (c153c7e)

Features

  • use alasql instead of lokijs (d6c5b72)

0.2.0-beta.2 (2023-12-05)

Bug Fixes

  • improved metadata for optionsets (c153c7e)

0.2.0-beta.1 (2023-12-02)

Features

  • use alasql instead of lokijs (d6c5b72)

0.1.26 (2023-11-27)

Bug Fixes

  • Added support for dataset CUD operations (80cdb09)

0.1.25 (2023-10-04)

Bug Fixes

  • trackContainerResize for virtual components (0ade007)

0.1.24 (2023-10-01)

Bug Fixes

0.1.23 (2023-03-03)

Bug Fixes

  • Fixed a bug with virtual componenents not refreshing datasets (eaf43af)

0.1.22 (2023-03-01)

Bug Fixes

  • Fixed an issue with dataset refresh being called multiple times (c087351)

0.1.21 (2023-02-27)

Bug Fixes

  • Changing fullscreen correctly calls updateView (76eaf02)
  • Dataset should load with a delay (cee23dd)

0.1.20 (2023-02-25)

Bug Fixes

  • Fixed some bugs with the in-memory DB (ee2ef7a)

0.1.19 (2023-02-24)

Bug Fixes

  • dataset autogenerates record id (5ef9be8)

0.1.18 (2023-02-16)

Bug Fixes

  • Correctly fixed enum types (298b740)

0.1.17 (2023-02-16)

Bug Fixes

  • Fixed embedded types for Enums (d080122)

0.1.16 (2023-02-15)

Bug Fixes

  • added readme to npm package (c53061c)

0.1.15 (2023-02-12)

Bug Fixes

  • fixed bundled types (8552ffd)
  • Implemented WebAPI.create and delete (9374860)
  • WebApi RetrieveRecord (61f1ca1)

0.1.14 (2023-02-08)

Bug Fixes

  • Added _SetValue helper function (4a05133)

0.1.13 (2023-01-31)

Bug Fixes

  • Fixed updatedProperties for Dates (f9908b0)

0.1.12 (2022-12-29)

Bug Fixes

  • Fixed types import/export (9ca9d91)

0.1.11 (2022-12-29)

Bug Fixes

  • Fixed types import/export (a29943b)

0.1.10 (2022-12-28)

Bug Fixes

  • Fixed a problem with Lookup values on update (76fc339)