by
4,027 19
1
5
730
0
Top 5% !
Popular
Tagged
Specified
OpenSource
Created
Modified Apr 25, 2018

Published on:

Languagejavascript
LicenseMIT_X11

unit testing - mocking server responses with sinonjs

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/3657638/unit-testing---mocking-server-responses-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
{ setUp: function () { this.server = sinon.fakeServer.create(); }, tearDown: function () { this.server.restore(); }, "test should fetch comments from server" : function () { this.server.respondWith("GET", "/some/article/comments.json", [200, { "Content-Type": "application/json" }, '[{ "id": 12, "comment": "Hey there" }]']); var callback = sinon.spy(); myLib.getCommentsFor("/some/article", callback); this.server.respond(); sinon.assert.calledWith(callback, [{ id: 12, comment: "Hey there" }])); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus