Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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