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.
For the latest stable version
npm install xrm-mock -D
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);
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.
export default class Contact {
public static onLoad() {
Xrm.Page.getAttribute("firstname").setValue("Bob");
}
}
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
});
});
- 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
- Test your code using
- Increased test coverage
- Increased implementation against different versions of
@types/Xrm
(8.2 and 9) - Automatic generation of attributes from a given Dynamics organisation