This project is read-only.
Project Description
A mock/fake implementation of the CRM 2011, 2013 and CRM online Xrm Page object designed for unit testing Form Scripts using TypeScript or standard JavaScript.

Unit Testing

To run unit tests for scripts normally running on CRM forms you need a working version of the CRM Xrm Page object. This is object contains lots of information and can be difficult to fake. The FakeXrmPage object allows you to load all this information from a customizations file. This makes testing easier and results in a more reliable. Defining unit tests allows you to quickly run a verification of the operation of your scripts.

Work in Progress

The current implementation contains most of the functionality provided by the Xrm Page object. Some methods have not been implemented. These throw an error (Not Implemented).

Source Code/Documentation

In the source code section a full project is available which includes the Fake XrmPage script files including jasmine with a few test cases showing the how to use the solution. To run the samples you must add a customizations.xml file (extracted from an unmanaged CRM solution containing at least the account entity) to the same folder as the SpecRunner.html file.
The project also contains a simple example of a account form script with related unit tests.
The project is implemented using TypeScript. You can use the generated javascript file (FakeXrmPage.js) for non-typescript projects.

Project contents

  • Scripts
    • FakeXrmPage
      • FakeXrmPage.ts: The file containing the implementation of the Fake XrmPage object
      • FakeXrmPage.Tests.ts: Some tests showing example of how to use the Fake XrmPage object
      • Account Form Example.ts: Example of a simple CRM form script
      • Account Form Example.Tests.test: Example of unit tests
    • jasmine: A javascript test host
      • Jasmine.Typed.ts: Class to support creating jasmine unit tests in TypeScript
    • typings: Various .d.ts files for non-TypeScript projects
      • xrmpage: Contains a full Type-Script Definition file for the Xrm Page model. This can be used standalone for development of TypeScript CRM script webresources.
  • SpecRunner.html: Entry point to execute the Jasmine tests

Using Fake XrmPage

For your own TypeScript projects you need to copy the FakeXrmPage.ts, XrmPage.d.ts, jquery.d.ts files and provide a reference to jquery (1.10/2.0).
For JavaScript projects (non-TypeSCript) you only need to copy the FakeXrmPage.js file generated by Visual Studio (or tsc) and provide a reference to jquery (1.10/2.0).
For some more information also see


The project requires visual studio 2013 with web essentials.
The project uses NuGet packages to load its dependencies (jQuery, Jasmine, TypeScript definitions)
  • jQuery is used to parse the xml file.
  • Jasmine (2.0) is used to run the unit tests. You can replace this with any other testing framework. Jasmine is only required to run the provided examples.

Known issues

  1. At present not all method of the Xrm Page object have been implemented.
  2. Performance when loading the customizations.xml is fairly slow

Last edited Jun 26, 2014 at 10:14 AM by patrickverbeeten, version 6