@wycliffeassociates/xrm-mock
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

xrm-mock

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

Build Chat NPM Coverage Vulnerabilities Climate
Build Status Join the chat at https://gitter.im/xrm-mock/Lobby NPM Coverage Status Known Vulnerabilities Code Climate

📚 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
    });
});

❤️  Contributing and Project Roadmap:

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

Package Sidebar

Install

npm i @wycliffeassociates/xrm-mock

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • vickyleong