Giter VIP home page Giter VIP logo

xrm-mock's Introduction

Build Status npm version Downloads Test Coverage

๐Ÿ“š xrm-mock

Join the chat at https://gitter.im/xrm-mock/Lobby

xrm-mock is a fake implementation of the Dynamics 365 Client API and Xrm object model. Written in TypeScript against @types/xrm definitions.

xrm-mock-generator is an opinionated toolset for building fake Xrm objects.

Installing

For the latest stable version

npm install xrm-mock -D

Usage

Import XrmMockGenerator in your unit test file

import { XrmMockGenerator } from "xrm-mock";

Initialise a global Xrm object

XrmMockGenerator.initialise();

Customise your form by adding attributes

XrmMockGenerator.Attribute.createBool("new_havingfun", true);

Invoke your code and make your assertions

Contact.onLoad();
expect(Xrm.Page.getAttribute("new_havingfun").getValue()).toBe(true);

Example

This example demonstrates a script with an onLoad event handler registered on a contact form. When invoked, it changes the firstname attribute's value to Bob. See the Wiki for a visual demo.

src/contact.ts

export default class Contact {
 public static onLoad() {
   Xrm.Page.getAttribute("firstname").setValue("Bob");
 }
}

test/contact.test.ts

import Contact from "../src/contact";
import { XrmMockGenerator } from "xrm-mock";

describe("Contact", () => {
  beforeEach(() => {
    XrmMockGenerator.initialise();
    XrmMockGenerator.Attribute.createString("firstname", "Joe");
  });

  it("should initially be called Joe", () => {
    let name = Xrm.Page.getAttribute("firstname").getValue();
    expect(name).toBe("Joe"); // Pass
  });

  it("should change name to Bob onLoad", () => {
    Contact.onLoad();
    let name = Xrm.Page.getAttribute("firstname").getValue();
    expect(name).toBe("Bob"); // Pass
  });
});

Contribute

  • Submit bugs
  • Implement a new function by inheriting @types/Xrm
    • Test your code using npm run test
    • Lint your code using npm run lint
    • Build your code using npm run build

Roadmap

  • Increased test coverage
  • Increased implementation against different versions of @types/Xrm (8.2 and 9)
  • Automatic generation of attributes from a given Dynamics organisation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.