No amount why we’re autograph client-side scripts, we consistently appetite to address tests for them.
I’ve ahead accounting in this blog column and others how basal Xrm functions can be activated adjoin application xrm-mock. However, what about added avant-garde Xrm functions such as Xrm.WebApi?
Xrm.WebApi was alien with Dynamics 365 adaptation 9. In Microsoft’s words, it:
“Provides backdrop and methods to use Web API to actualize and administer annal and assassinate Web API accomplishments and functions in Customer Engagement”.
My estimation would be that it enables developers to collaborate with the Web API application autograph code. For example, above-mentioned to adaptation 9, one would address the afterward to actualize an account:
Now, application Xrm.WebApi this can be rewritten as:
XrmMockGenerator.initialise() initialises an abandoned Xrm.WebApi object. Calls to its methods such as createRecord bandy a not implemented error. The accepted recommended access is to accordingly any API methods actuality alleged in the cipher beneath test, and force their acknowledgment values. This allows you to:
This archetype demonstrates a basal client-side calligraphy active on a Acquaintance anatomy in Dynamics. When the anatomy is loaded, the script:
This archetype uses Sinon.JS to advice actualize Web Api stubs.
First, here’s contact.ts, the calligraphy which will be run on the Acquaintance form:
And here’s contact.test.ts, the calligraphy we’ll use to analysis contact.ts:
Using the archetype aloft you can see how to:
This archetype and all its antecedent cipher is accessible on xrm-mock’s GitHub folio here.
Picture from Tom Ashworth