xrm-mock is a package that lets you generate a fake implementation of the Xrm object in your client-side code, allowing you to unit test your scripts.
How do I install it?
Simply download xrm-mock's npm package by running
npm install xrm-mock -D
import { XrmMockGenerator } from "xrm-mock";
XrmMockGenerator.initialise();
Here's how you add basic attributes:
Now for a lookup attribute: And finally an option set attribute:
See xrm-mock's readme and Wiki for examples of how to unit test against your newly created attributes.
What's changed in v3?
As part of xrm-mock v3 release, attribute create methods only need two arguments: a schema name and a value, as shown in the above code snippet.
Why xrm-mock?
Faking Xrm is hard and time consuming: it has several nested objects which require a detailed understanding to fake correctly. xrm-mock is gaining traction with the open source community, and can expect to see more releases in the coming months. In fact, Daryl LaBar has become a contributor and he's already hit the ground running.
Hi, I get an error when I do XrmMockGenerator.initialise();
ReplyDeleteFor example:
var XrmMockGenerator = require("xrm-mock");
XrmMockGenerator.initialise();
ERROR: TypeError: XrmMockGenerator.initialise is not a function