0.0.1 • Published 7 years ago

@wycliffeassociates/xrm-mock v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

xrm-mock

A mock implementation of the Xrm.Page object model. Written in TypeScript against @types/xrm definitions.

BuildChatNPMCoverageVulnerabilitiesClimate
Build StatusJoin the chat at https://gitter.im/xrm-mock/LobbyNPMCoverage StatusKnown VulnerabilitiesCode Climate

:books: Usage:

  • Clone, Fork or install the repository via npm i xrm-mock

  • Install generation tool npm i xrm-mock-generator [link] (biased recommendation)

  • Create a file for your entity form:

    src/contact.js

    (function () {
       "use strict";
       
       var Contact = () => {  };
       
       Contact.prototype.onLoad = () => {
           Xrm.Page.getAttribute("firstname").setValue("Bob");
       }
       
       // node
       module.exports = new Contact();
       
       // browser
       global.Contact = new Contact();    
    }());
  • Create a file to test your entity form:

test/contact.test.js

describe("Contact Form", () => {
    var XrmMockGenerator = require("xrm-mock-generator");
    var ContactForm = require("../src/contact.js");
    
    beforeEach(() => {
        XrmMockGenerator.initialise();
        XrmMockGenerator.createString("firstname", "Joe");
    });
    
    describe("default", () => {
        expect(Xrm.Page.getAttribute("firstname").getValue()).toBe("Joe"); // true
    });
    
    describe("onLoad", () => {
        ContactForm.onLoad();        
        expect(Xrm.Page.getAttribute("firstname").getValue()).toBe("Bob"); // true
    });
});

:heart:  Contributing and Project Roadmap:

  • Increase test coverage
  • Increase implementation
  • Include a project like rewire so that non-exported classes can be tested