A mock implementation of the Xrm.Page object model. Written in TypeScript against @types/xrm definitions.
-
Clone the repository
-
Install node dependencies with
cd repo-dir
andnpm i
from a command line -
Create a
.ts
file for your entity form:
module ProjectName {
export class Contact {
Xrm: Xrm.Static;
}
constructor(xrm?: Xrm.XrmStatic) {
this.Xrm = xrm;
}
onLoad(): void {
if (this.Xrm) { Xrm = this.Xrm; }
// ...
}
}
- Create a
.ts
file to test your entity form:
// This example uses Jasmine
describe('Contact', function() {
beforeEach(function () {
let attributes: AttributeMock[] = [];
attributes.push(new AttributeMock('firstname', 'Joe', false, 'none'));
attributes.push(new AttributeMock('lastname', 'Bloggs', true, 'recommended', 'always'));
this.XrmMock = new XrmStaticMock(
new PageMock(
new DataMock(
new EntityMock(
new ItemCollectionMock<AttributeMock>(attributes)))));
this.contact = new ProjectName.Contact(this.XrmMock);
this.contact.onLoad();
});
// Describe the expected behaviour of the Contact form after onLoad() is invoked.
describe('onLoad', function () {
it('behaves like this', function () {
expect(this.contact).toBeDefined();
// ...
});
});
}