Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
Created May 13, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jhartikainen/91061b182f6cb37a63313805d4d7cd8d to your computer and use it in GitHub Desktop.
Save jhartikainen/91061b182f6cb37a63313805d4d7cd8d to your computer and use it in GitHub Desktop.
Example of stubbing a complex object
describe('something', function() {
var oldXrm;
beforeEach(function() {
oldXrm = Xrm;
Xrm = {
Page: {
getAttribute: sinon.stub()
}
};
});
afterEach(function() {
Xrm = oldXrm;
});
it('tests something', function() {
var fakeAttribute = {
getValue: function() { return 'something'; }
};
Xrm.Page.getAttribute.withArgs('name').returns(fakeAttribute);
//test code here
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment