Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created September 3, 2011 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxriverlynn/1191641 to your computer and use it in GitHub Desktop.
Save mxriverlynn/1191641 to your computer and use it in GitHub Desktop.
custom jasmine matcher for index of 'selected' image
describe("when no image is selected and previous is called", function(){
beforeEach(function(){
this.images.previous();
});
it("should select the last image", function(){
var lastImage = imageList.length-1;
var selectedImage = this.images.indexOf(this.images.selectedImage);
expect(selectedImage).toBe(lastImage);
});
});
describe("when no image is selected and previous is called", function(){
beforeEach(function(){
this.images.previous();
});
it("should select the last image", function(){
expect(this.images).toHaveSelectedImageAt(imageList.length-1);
});
});
beforeEach(function() {
this.addMatchers({
toHaveSelectedImageAt: function(expectedIndex) {
var images = this.actual;
var actualIndex = images.indexOf(images.selectedImage);
this.actual = actualIndex;
this.message = function(){
return "Expected selected image index of " + actualIndex + " to be " + expectedIndex;
};
return (actualIndex == expectedIndex);;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment