Created
September 3, 2011 19:24
-
-
Save mxriverlynn/1191641 to your computer and use it in GitHub Desktop.
custom jasmine matcher for index of 'selected' image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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