npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shko.online/componentframework-mock

v0.6.3

Published

Mocking library to help with testing PowerApps Component Framework Components

Downloads

2,754

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.