Created
January 16, 2017 13:35
-
-
Save delwar2016/0dcb4bec69c3892e77d5bd4a916fb8ac to your computer and use it in GitHub Desktop.
How to stub jQuery remove using sinonJS
This file contains hidden or 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
Suppose we have following situation | |
$('#dom1').remove(); | |
$('#dom2').remove(); | |
$('#dom3').remove(); | |
$('#dom4').remove(); | |
So, we can write unit test as follows: | |
this.removeStub = sinon.stub($.fn, 'remove'); | |
it('Should remove dom', function(){ | |
expect(this.removeStub.callCount).to.equal(4); | |
expect(this.removeStub.thisValues[0].selector).to.be.equal('#dom1'); | |
expect(this.removeStub.thisValues[1].selector).to.be.equal('#dom2'); | |
expect(this.removeStub.thisValues[2].selector).to.be.equal('#dom3'); | |
expect(this.removeStub.thisValues[3].selector).to.be.equal('#dom4'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment