From 345cccaf4f5006751c00cbf3403775aeb94bfd02 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Fri, 13 Sep 2024 01:06:44 +0200 Subject: [PATCH] Deployed 034b176 with MkDocs version: 1.2.3 --- index.html | 4 ++-- search/search_index.json | 2 +- sitemap.xml | 2 +- sitemap.xml.gz | Bin 189 -> 189 bytes 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index a20ccf5..8985ccc 100644 --- a/index.html +++ b/index.html @@ -342,7 +342,7 @@

var server = fakeServer.create(

This function also calls useFakeXMLHttpRequest().

create accepts optional properties to configure the fake server. See options below for configuration parameters.

var server = fakeServerWithClock.create();

-

Creates a server that also manages fake timers.

+

Creates a server that also manages fake timers.

This is useful when testing XHR objects created with e.g. jQuery 1.3.x, which uses a timer to poll the object for completion, rather than the usual onreadystatechange.

server.configure(config);

Configures the fake server.

@@ -473,5 +473,5 @@

boolean fakeHTTPMethods

diff --git a/search/search_index.json b/search/search_index.json index 47584c9..81e3612 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"nise (\u507d) fake XHR and Server This module has been extracted from Sinon.JS and can be used standalone. Sinon.JS will always be the \"full package\". However, there are use cases, where fake XHR and fake Server are needed but the rest of Sinon.JS not. That's the scenario of nise. Fake XMLHttpRequest Provides a fake implementation of XMLHttpRequest and provides several interfaces for manipulating objects created by it. Also fakes native XMLHttpRequest and ActiveXObject (when available, and only for XMLHTTP progids). Helps with testing requests made with XHR . var fakeXhr = require(\"nise\").fakeXhr; var sinon = require(\"sinon\"); { setUp: function () { this.xhr = fakeXhr.useFakeXMLHttpRequest(); var requests = this.requests = []; this.xhr.onCreate = function (xhr) { requests.push(xhr); }; }, tearDown: function () { this.xhr.restore(); }, \"test should fetch comments from server\" : function () { var callback = sinon.spy(); myLib.getCommentsFor(\"/some/article\", callback); assertEquals(1, this.requests.length); this.requests[0].respond(200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": 12, \"comment\": \"Hey there\" }]'); assert(callback.calledWith([{ id: 12, comment: \"Hey there\" }])); } } useFakeXMLHttpRequest var xhr = fakeXhr.useFakeXMLHttpRequest(); Causes fakeXhr to replace the native XMLHttpRequest object in browsers that support it with a custom implementation which does not send actual requests. In browsers that support ActiveXObject , this constructor is replaced, and fake objects are returned for XMLHTTP progIds. Other progIds, such as XMLDOM are left untouched. The native XMLHttpRequest object will be available at fakeXhr.xhr.XMLHttpRequest xhr.onCreate = function (xhr) {}; By assigning a function to the onCreate property of the returned object from useFakeXMLHttpRequest() you can subscribe to newly created FakeXMLHttpRequest objects. See below for the fake xhr object API. Using this observer means you can still reach objects created by e.g. jQuery.ajax (or other abstractions/frameworks). xhr.restore(); Restore original function(s). FakeXMLHttpRequest String request.url The URL set on the request object. String request.method The request method as a string. Object request.requestHeaders An object of all request headers, i.e.: { \"Accept\": \"text/html, */*\", \"Connection\": \"keep-alive\" } String request.requestBody The request body int request.status The request's status code. undefined if the request has not been handled (see respond below) String request.statusText Only populated if the respond method is called (see below). boolean request.async Whether or not the request is asynchronous. String request.username Username, if any. String request.password Password, if any. Document request.responseXML When using respond , this property is populated with a parsed document if response headers indicate as much (see the spec ) String request.getResponseHeader(header); The value of the given response header, if the request has been responded to (see respond ). Object request.getAllResponseHeaders(); All response headers as an object. Filtered requests When using Sinon.JS for mockups or partial integration/functional testing, you might want to fake some requests, while allowing others to go through to the backend server. With filtered FakeXMLHttpRequest s (new in v1.3.0), you can. FakeXMLHttpRequest.useFilters Default false . When set to true , Sinon will check added filters if certain requests should be \"unfaked\" FakeXMLHttpRequest.addFilter(fn) Add a filter that will decide whether or not to fake a request. The filter will be called when xhr.open is called, with the exact same arguments ( method , url , async , username , password ). If the filter returns true , the request will not be faked. Simulating server responses request.setStatus(status); Sets response status ( status and statusText properties). Status should be a number, the status text is looked up from fakeXhr.FakeXMLHttpRequest.statusCodes . request.setResponseHeaders(object); Sets response headers (e.g. { \"Content-Type\": \"text/html\", /* ... */ } , updates the readyState property and fires onreadystatechange . request.setResponseBody(body); Sets the respond body, updates the readyState property and fires onreadystatechange . Additionally, populates responseXML with a parsed document if response headers indicate as much . request.respond(status, headers, body); Calls the above three methods. request.error(); Simulates a network error on the request. The onerror handler will be called and the status will be 0 . Boolean request.autoRespond When set to true , causes the server to automatically respond to incoming requests after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. Number request.autoRespondAfter When autoRespond is true , respond to requests after this number of milliseconds. Default is 10. Fake server High-level API to manipulate FakeXMLHttpRequest instances. For help with handling JSON-P please refer to our notes below var fakeServer = require(\"nise\").fakeServer; var sinon = require(\"sinon\"); { setUp: function () { this.server = 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\" }]); assert(server.requests.length > 0) } } var server = fakeServer.create([config]); Creates a new server. This function also calls useFakeXMLHttpRequest() . create accepts optional properties to configure the fake server. See options below for configuration parameters. var server = fakeServerWithClock.create(); Creates a server that also manages fake timers. This is useful when testing XHR objects created with e.g. jQuery 1.3.x, which uses a timer to poll the object for completion, rather than the usual onreadystatechange . server.configure(config); Configures the fake server. See options below for configuration parameters. server.respondWith(response); Causes the server to respond to any request not matched by another response with the provided data. The default catch-all response is [404, {}, \"\"] . response can be one of three things: A String or ArrayBuffer representing the response body An Array with status, headers and response body, e.g. [200, { \"Content-Type\": \"text/html\", \"Content-Length\": 2 }, \"OK\"] A Function . Default status is 200 and default headers are none. When the response is a Function , it will be passed the request object. You must manually call respond on it to complete the request. server.respondWith(url, response); Responds to all requests to given URL, e.g. /posts/1 . server.respondWith(method, url, response); Responds to all method requests to the given URL with the given response. method is an HTTP verb. server.respondWith(urlRegExp, response); URL may be a regular expression, e.g. /\\\\/post\\\\//\\\\d+ If the response is a Function , it will be passed any capture groups from the regular expression along with the XMLHttpRequest object: server.respondWith(/\\/todo-items\\/(\\d+)/, function (xhr, id) { xhr.respond( 200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": ' + id + \" }]\", ); }); server.respondWith(method, urlRegExp, response); Responds to all method requests to URLs matching the regular expression. server.respond(); Causes all queued asynchronous requests to receive a response. If none of the responses added through respondWith match, the default response is [404, {}, \"\"] . Synchronous requests are responded to immediately, so make sure to call respondWith upfront. If called with arguments, respondWith will be called with those arguments before responding to requests. server.autoRespond = true; If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead. server.autoRespondAfter = ms; Causes the server to automatically respond to incoming requests after a timeout. server.respondImmediately = true; If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter . array server.requests You can inspect the server.requests to verify request ordering, find unmatched requests or check that no requests has been done. server.requests is an array of all the FakeXMLHttpRequest objects that have been created. Boolean server.fakeHTTPMethods If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request) . server.getHTTPMethod(request) Used internally to determine the HTTP method used with the provided request. By default this method simply returns request.method . When server.fakeHTTPMethods is true, the method will return the value of the _method parameter if the method is \"POST\". This method can be overridden to provide custom behavior. server.restore(); Restores the native XHR constructor. Fake server options These options are properties on the server object and can be set directly server.autoRespond = true; You can also pass options with an object literal to fakeServer.create and .configure . Boolean autoRespond If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead. Number autoRespondAfter (ms) Causes the server to automatically respond to incoming requests after a timeout. Boolean respondImmediately If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter . boolean fakeHTTPMethods If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request)","title":"nise (\u507d)"},{"location":"#nise","text":"fake XHR and Server This module has been extracted from Sinon.JS and can be used standalone. Sinon.JS will always be the \"full package\". However, there are use cases, where fake XHR and fake Server are needed but the rest of Sinon.JS not. That's the scenario of nise.","title":"nise (\u507d)"},{"location":"#fake-xmlhttprequest","text":"Provides a fake implementation of XMLHttpRequest and provides several interfaces for manipulating objects created by it. Also fakes native XMLHttpRequest and ActiveXObject (when available, and only for XMLHTTP progids). Helps with testing requests made with XHR . var fakeXhr = require(\"nise\").fakeXhr; var sinon = require(\"sinon\"); { setUp: function () { this.xhr = fakeXhr.useFakeXMLHttpRequest(); var requests = this.requests = []; this.xhr.onCreate = function (xhr) { requests.push(xhr); }; }, tearDown: function () { this.xhr.restore(); }, \"test should fetch comments from server\" : function () { var callback = sinon.spy(); myLib.getCommentsFor(\"/some/article\", callback); assertEquals(1, this.requests.length); this.requests[0].respond(200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": 12, \"comment\": \"Hey there\" }]'); assert(callback.calledWith([{ id: 12, comment: \"Hey there\" }])); } }","title":"Fake XMLHttpRequest"},{"location":"#usefakexmlhttprequest","text":"","title":"useFakeXMLHttpRequest"},{"location":"#var-xhr-fakexhrusefakexmlhttprequest","text":"Causes fakeXhr to replace the native XMLHttpRequest object in browsers that support it with a custom implementation which does not send actual requests. In browsers that support ActiveXObject , this constructor is replaced, and fake objects are returned for XMLHTTP progIds. Other progIds, such as XMLDOM are left untouched. The native XMLHttpRequest object will be available at fakeXhr.xhr.XMLHttpRequest","title":"var xhr = fakeXhr.useFakeXMLHttpRequest();"},{"location":"#xhroncreate-function-xhr","text":"By assigning a function to the onCreate property of the returned object from useFakeXMLHttpRequest() you can subscribe to newly created FakeXMLHttpRequest objects. See below for the fake xhr object API. Using this observer means you can still reach objects created by e.g. jQuery.ajax (or other abstractions/frameworks).","title":"xhr.onCreate = function (xhr) {};"},{"location":"#xhrrestore","text":"Restore original function(s).","title":"xhr.restore();"},{"location":"#fakexmlhttprequest","text":"","title":"FakeXMLHttpRequest"},{"location":"#string-requesturl","text":"The URL set on the request object.","title":"String request.url"},{"location":"#string-requestmethod","text":"The request method as a string.","title":"String request.method"},{"location":"#object-requestrequestheaders","text":"An object of all request headers, i.e.: { \"Accept\": \"text/html, */*\", \"Connection\": \"keep-alive\" }","title":"Object request.requestHeaders"},{"location":"#string-requestrequestbody","text":"The request body","title":"String request.requestBody"},{"location":"#int-requeststatus","text":"The request's status code. undefined if the request has not been handled (see respond below)","title":"int request.status"},{"location":"#string-requeststatustext","text":"Only populated if the respond method is called (see below).","title":"String request.statusText"},{"location":"#boolean-requestasync","text":"Whether or not the request is asynchronous.","title":"boolean request.async"},{"location":"#string-requestusername","text":"Username, if any.","title":"String request.username"},{"location":"#string-requestpassword","text":"Password, if any.","title":"String request.password"},{"location":"#document-requestresponsexml","text":"When using respond , this property is populated with a parsed document if response headers indicate as much (see the spec )","title":"Document request.responseXML"},{"location":"#string-requestgetresponseheaderheader","text":"The value of the given response header, if the request has been responded to (see respond ).","title":"String request.getResponseHeader(header);"},{"location":"#object-requestgetallresponseheaders","text":"All response headers as an object.","title":"Object request.getAllResponseHeaders();"},{"location":"#filtered-requests","text":"When using Sinon.JS for mockups or partial integration/functional testing, you might want to fake some requests, while allowing others to go through to the backend server. With filtered FakeXMLHttpRequest s (new in v1.3.0), you can.","title":"Filtered requests"},{"location":"#fakexmlhttprequestusefilters","text":"Default false . When set to true , Sinon will check added filters if certain requests should be \"unfaked\"","title":"FakeXMLHttpRequest.useFilters"},{"location":"#fakexmlhttprequestaddfilterfn","text":"Add a filter that will decide whether or not to fake a request. The filter will be called when xhr.open is called, with the exact same arguments ( method , url , async , username , password ). If the filter returns true , the request will not be faked.","title":"FakeXMLHttpRequest.addFilter(fn)"},{"location":"#simulating-server-responses","text":"","title":"Simulating server responses"},{"location":"#requestsetstatusstatus","text":"Sets response status ( status and statusText properties). Status should be a number, the status text is looked up from fakeXhr.FakeXMLHttpRequest.statusCodes .","title":"request.setStatus(status);"},{"location":"#requestsetresponseheadersobject","text":"Sets response headers (e.g. { \"Content-Type\": \"text/html\", /* ... */ } , updates the readyState property and fires onreadystatechange .","title":"request.setResponseHeaders(object);"},{"location":"#requestsetresponsebodybody","text":"Sets the respond body, updates the readyState property and fires onreadystatechange . Additionally, populates responseXML with a parsed document if response headers indicate as much .","title":"request.setResponseBody(body);"},{"location":"#requestrespondstatus-headers-body","text":"Calls the above three methods.","title":"request.respond(status, headers, body);"},{"location":"#requesterror","text":"Simulates a network error on the request. The onerror handler will be called and the status will be 0 .","title":"request.error();"},{"location":"#boolean-requestautorespond","text":"When set to true , causes the server to automatically respond to incoming requests after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests.","title":"Boolean request.autoRespond"},{"location":"#number-requestautorespondafter","text":"When autoRespond is true , respond to requests after this number of milliseconds. Default is 10.","title":"Number request.autoRespondAfter"},{"location":"#fake-server","text":"High-level API to manipulate FakeXMLHttpRequest instances. For help with handling JSON-P please refer to our notes below var fakeServer = require(\"nise\").fakeServer; var sinon = require(\"sinon\"); { setUp: function () { this.server = 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\" }]); assert(server.requests.length > 0) } }","title":"Fake server"},{"location":"#var-server-fakeservercreateconfig","text":"Creates a new server. This function also calls useFakeXMLHttpRequest() . create accepts optional properties to configure the fake server. See options below for configuration parameters.","title":"var server = fakeServer.create([config]);"},{"location":"#var-server-fakeserverwithclockcreate","text":"Creates a server that also manages fake timers. This is useful when testing XHR objects created with e.g. jQuery 1.3.x, which uses a timer to poll the object for completion, rather than the usual onreadystatechange .","title":"var server = fakeServerWithClock.create();"},{"location":"#serverconfigureconfig","text":"Configures the fake server. See options below for configuration parameters.","title":"server.configure(config);"},{"location":"#serverrespondwithresponse","text":"Causes the server to respond to any request not matched by another response with the provided data. The default catch-all response is [404, {}, \"\"] . response can be one of three things: A String or ArrayBuffer representing the response body An Array with status, headers and response body, e.g. [200, { \"Content-Type\": \"text/html\", \"Content-Length\": 2 }, \"OK\"] A Function . Default status is 200 and default headers are none. When the response is a Function , it will be passed the request object. You must manually call respond on it to complete the request.","title":"server.respondWith(response);"},{"location":"#serverrespondwithurl-response","text":"Responds to all requests to given URL, e.g. /posts/1 .","title":"server.respondWith(url, response);"},{"location":"#serverrespondwithmethod-url-response","text":"Responds to all method requests to the given URL with the given response. method is an HTTP verb.","title":"server.respondWith(method, url, response);"},{"location":"#serverrespondwithurlregexp-response","text":"URL may be a regular expression, e.g. /\\\\/post\\\\//\\\\d+ If the response is a Function , it will be passed any capture groups from the regular expression along with the XMLHttpRequest object: server.respondWith(/\\/todo-items\\/(\\d+)/, function (xhr, id) { xhr.respond( 200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": ' + id + \" }]\", ); });","title":"server.respondWith(urlRegExp, response);"},{"location":"#serverrespondwithmethod-urlregexp-response","text":"Responds to all method requests to URLs matching the regular expression.","title":"server.respondWith(method, urlRegExp, response);"},{"location":"#serverrespond","text":"Causes all queued asynchronous requests to receive a response. If none of the responses added through respondWith match, the default response is [404, {}, \"\"] . Synchronous requests are responded to immediately, so make sure to call respondWith upfront. If called with arguments, respondWith will be called with those arguments before responding to requests.","title":"server.respond();"},{"location":"#serverautorespond-true","text":"If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead.","title":"server.autoRespond = true;"},{"location":"#serverautorespondafter-ms","text":"Causes the server to automatically respond to incoming requests after a timeout.","title":"server.autoRespondAfter = ms;"},{"location":"#serverrespondimmediately-true","text":"If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter .","title":"server.respondImmediately = true;"},{"location":"#array-serverrequests","text":"You can inspect the server.requests to verify request ordering, find unmatched requests or check that no requests has been done. server.requests is an array of all the FakeXMLHttpRequest objects that have been created.","title":"array server.requests"},{"location":"#boolean-serverfakehttpmethods","text":"If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request) .","title":"Boolean server.fakeHTTPMethods"},{"location":"#servergethttpmethodrequest","text":"Used internally to determine the HTTP method used with the provided request. By default this method simply returns request.method . When server.fakeHTTPMethods is true, the method will return the value of the _method parameter if the method is \"POST\". This method can be overridden to provide custom behavior.","title":"server.getHTTPMethod(request)"},{"location":"#serverrestore","text":"Restores the native XHR constructor.","title":"server.restore();"},{"location":"#fake-server-options","text":"These options are properties on the server object and can be set directly server.autoRespond = true; You can also pass options with an object literal to fakeServer.create and .configure .","title":"Fake server options"},{"location":"#boolean-autorespond","text":"If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead.","title":"Boolean autoRespond"},{"location":"#number-autorespondafter-ms","text":"Causes the server to automatically respond to incoming requests after a timeout.","title":"Number autoRespondAfter (ms)"},{"location":"#boolean-respondimmediately","text":"If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter .","title":"Boolean respondImmediately"},{"location":"#boolean-fakehttpmethods","text":"If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request)","title":"boolean fakeHTTPMethods"}]} \ No newline at end of file +{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"nise (\u507d) fake XHR and Server This module has been extracted from Sinon.JS and can be used standalone. Sinon.JS will always be the \"full package\". However, there are use cases, where fake XHR and fake Server are needed but the rest of Sinon.JS not. That's the scenario of nise. Fake XMLHttpRequest Provides a fake implementation of XMLHttpRequest and provides several interfaces for manipulating objects created by it. Also fakes native XMLHttpRequest and ActiveXObject (when available, and only for XMLHTTP progids). Helps with testing requests made with XHR . var fakeXhr = require(\"nise\").fakeXhr; var sinon = require(\"sinon\"); { setUp: function () { this.xhr = fakeXhr.useFakeXMLHttpRequest(); var requests = this.requests = []; this.xhr.onCreate = function (xhr) { requests.push(xhr); }; }, tearDown: function () { this.xhr.restore(); }, \"test should fetch comments from server\" : function () { var callback = sinon.spy(); myLib.getCommentsFor(\"/some/article\", callback); assertEquals(1, this.requests.length); this.requests[0].respond(200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": 12, \"comment\": \"Hey there\" }]'); assert(callback.calledWith([{ id: 12, comment: \"Hey there\" }])); } } useFakeXMLHttpRequest var xhr = fakeXhr.useFakeXMLHttpRequest(); Causes fakeXhr to replace the native XMLHttpRequest object in browsers that support it with a custom implementation which does not send actual requests. In browsers that support ActiveXObject , this constructor is replaced, and fake objects are returned for XMLHTTP progIds. Other progIds, such as XMLDOM are left untouched. The native XMLHttpRequest object will be available at fakeXhr.xhr.XMLHttpRequest xhr.onCreate = function (xhr) {}; By assigning a function to the onCreate property of the returned object from useFakeXMLHttpRequest() you can subscribe to newly created FakeXMLHttpRequest objects. See below for the fake xhr object API. Using this observer means you can still reach objects created by e.g. jQuery.ajax (or other abstractions/frameworks). xhr.restore(); Restore original function(s). FakeXMLHttpRequest String request.url The URL set on the request object. String request.method The request method as a string. Object request.requestHeaders An object of all request headers, i.e.: { \"Accept\": \"text/html, */*\", \"Connection\": \"keep-alive\" } String request.requestBody The request body int request.status The request's status code. undefined if the request has not been handled (see respond below) String request.statusText Only populated if the respond method is called (see below). boolean request.async Whether or not the request is asynchronous. String request.username Username, if any. String request.password Password, if any. Document request.responseXML When using respond , this property is populated with a parsed document if response headers indicate as much (see the spec ) String request.getResponseHeader(header); The value of the given response header, if the request has been responded to (see respond ). Object request.getAllResponseHeaders(); All response headers as an object. Filtered requests When using Sinon.JS for mockups or partial integration/functional testing, you might want to fake some requests, while allowing others to go through to the backend server. With filtered FakeXMLHttpRequest s (new in v1.3.0), you can. FakeXMLHttpRequest.useFilters Default false . When set to true , Sinon will check added filters if certain requests should be \"unfaked\" FakeXMLHttpRequest.addFilter(fn) Add a filter that will decide whether or not to fake a request. The filter will be called when xhr.open is called, with the exact same arguments ( method , url , async , username , password ). If the filter returns true , the request will not be faked. Simulating server responses request.setStatus(status); Sets response status ( status and statusText properties). Status should be a number, the status text is looked up from fakeXhr.FakeXMLHttpRequest.statusCodes . request.setResponseHeaders(object); Sets response headers (e.g. { \"Content-Type\": \"text/html\", /* ... */ } , updates the readyState property and fires onreadystatechange . request.setResponseBody(body); Sets the respond body, updates the readyState property and fires onreadystatechange . Additionally, populates responseXML with a parsed document if response headers indicate as much . request.respond(status, headers, body); Calls the above three methods. request.error(); Simulates a network error on the request. The onerror handler will be called and the status will be 0 . Boolean request.autoRespond When set to true , causes the server to automatically respond to incoming requests after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. Number request.autoRespondAfter When autoRespond is true , respond to requests after this number of milliseconds. Default is 10. Fake server High-level API to manipulate FakeXMLHttpRequest instances. For help with handling JSON-P please refer to our notes below var fakeServer = require(\"nise\").fakeServer; var sinon = require(\"sinon\"); { setUp: function () { this.server = 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\" }]); assert(server.requests.length > 0) } } var server = fakeServer.create([config]); Creates a new server. This function also calls useFakeXMLHttpRequest() . create accepts optional properties to configure the fake server. See options below for configuration parameters. var server = fakeServerWithClock.create(); Creates a server that also manages fake timers . This is useful when testing XHR objects created with e.g. jQuery 1.3.x, which uses a timer to poll the object for completion, rather than the usual onreadystatechange . server.configure(config); Configures the fake server. See options below for configuration parameters. server.respondWith(response); Causes the server to respond to any request not matched by another response with the provided data. The default catch-all response is [404, {}, \"\"] . response can be one of three things: A String or ArrayBuffer representing the response body An Array with status, headers and response body, e.g. [200, { \"Content-Type\": \"text/html\", \"Content-Length\": 2 }, \"OK\"] A Function . Default status is 200 and default headers are none. When the response is a Function , it will be passed the request object. You must manually call respond on it to complete the request. server.respondWith(url, response); Responds to all requests to given URL, e.g. /posts/1 . server.respondWith(method, url, response); Responds to all method requests to the given URL with the given response. method is an HTTP verb. server.respondWith(urlRegExp, response); URL may be a regular expression, e.g. /\\\\/post\\\\//\\\\d+ If the response is a Function , it will be passed any capture groups from the regular expression along with the XMLHttpRequest object: server.respondWith(/\\/todo-items\\/(\\d+)/, function (xhr, id) { xhr.respond( 200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": ' + id + \" }]\", ); }); server.respondWith(method, urlRegExp, response); Responds to all method requests to URLs matching the regular expression. server.respond(); Causes all queued asynchronous requests to receive a response. If none of the responses added through respondWith match, the default response is [404, {}, \"\"] . Synchronous requests are responded to immediately, so make sure to call respondWith upfront. If called with arguments, respondWith will be called with those arguments before responding to requests. server.autoRespond = true; If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead. server.autoRespondAfter = ms; Causes the server to automatically respond to incoming requests after a timeout. server.respondImmediately = true; If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter . array server.requests You can inspect the server.requests to verify request ordering, find unmatched requests or check that no requests has been done. server.requests is an array of all the FakeXMLHttpRequest objects that have been created. Boolean server.fakeHTTPMethods If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request) . server.getHTTPMethod(request) Used internally to determine the HTTP method used with the provided request. By default this method simply returns request.method . When server.fakeHTTPMethods is true, the method will return the value of the _method parameter if the method is \"POST\". This method can be overridden to provide custom behavior. server.restore(); Restores the native XHR constructor. Fake server options These options are properties on the server object and can be set directly server.autoRespond = true; You can also pass options with an object literal to fakeServer.create and .configure . Boolean autoRespond If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead. Number autoRespondAfter (ms) Causes the server to automatically respond to incoming requests after a timeout. Boolean respondImmediately If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter . boolean fakeHTTPMethods If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request)","title":"nise (\u507d)"},{"location":"#nise","text":"fake XHR and Server This module has been extracted from Sinon.JS and can be used standalone. Sinon.JS will always be the \"full package\". However, there are use cases, where fake XHR and fake Server are needed but the rest of Sinon.JS not. That's the scenario of nise.","title":"nise (\u507d)"},{"location":"#fake-xmlhttprequest","text":"Provides a fake implementation of XMLHttpRequest and provides several interfaces for manipulating objects created by it. Also fakes native XMLHttpRequest and ActiveXObject (when available, and only for XMLHTTP progids). Helps with testing requests made with XHR . var fakeXhr = require(\"nise\").fakeXhr; var sinon = require(\"sinon\"); { setUp: function () { this.xhr = fakeXhr.useFakeXMLHttpRequest(); var requests = this.requests = []; this.xhr.onCreate = function (xhr) { requests.push(xhr); }; }, tearDown: function () { this.xhr.restore(); }, \"test should fetch comments from server\" : function () { var callback = sinon.spy(); myLib.getCommentsFor(\"/some/article\", callback); assertEquals(1, this.requests.length); this.requests[0].respond(200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": 12, \"comment\": \"Hey there\" }]'); assert(callback.calledWith([{ id: 12, comment: \"Hey there\" }])); } }","title":"Fake XMLHttpRequest"},{"location":"#usefakexmlhttprequest","text":"","title":"useFakeXMLHttpRequest"},{"location":"#var-xhr-fakexhrusefakexmlhttprequest","text":"Causes fakeXhr to replace the native XMLHttpRequest object in browsers that support it with a custom implementation which does not send actual requests. In browsers that support ActiveXObject , this constructor is replaced, and fake objects are returned for XMLHTTP progIds. Other progIds, such as XMLDOM are left untouched. The native XMLHttpRequest object will be available at fakeXhr.xhr.XMLHttpRequest","title":"var xhr = fakeXhr.useFakeXMLHttpRequest();"},{"location":"#xhroncreate-function-xhr","text":"By assigning a function to the onCreate property of the returned object from useFakeXMLHttpRequest() you can subscribe to newly created FakeXMLHttpRequest objects. See below for the fake xhr object API. Using this observer means you can still reach objects created by e.g. jQuery.ajax (or other abstractions/frameworks).","title":"xhr.onCreate = function (xhr) {};"},{"location":"#xhrrestore","text":"Restore original function(s).","title":"xhr.restore();"},{"location":"#fakexmlhttprequest","text":"","title":"FakeXMLHttpRequest"},{"location":"#string-requesturl","text":"The URL set on the request object.","title":"String request.url"},{"location":"#string-requestmethod","text":"The request method as a string.","title":"String request.method"},{"location":"#object-requestrequestheaders","text":"An object of all request headers, i.e.: { \"Accept\": \"text/html, */*\", \"Connection\": \"keep-alive\" }","title":"Object request.requestHeaders"},{"location":"#string-requestrequestbody","text":"The request body","title":"String request.requestBody"},{"location":"#int-requeststatus","text":"The request's status code. undefined if the request has not been handled (see respond below)","title":"int request.status"},{"location":"#string-requeststatustext","text":"Only populated if the respond method is called (see below).","title":"String request.statusText"},{"location":"#boolean-requestasync","text":"Whether or not the request is asynchronous.","title":"boolean request.async"},{"location":"#string-requestusername","text":"Username, if any.","title":"String request.username"},{"location":"#string-requestpassword","text":"Password, if any.","title":"String request.password"},{"location":"#document-requestresponsexml","text":"When using respond , this property is populated with a parsed document if response headers indicate as much (see the spec )","title":"Document request.responseXML"},{"location":"#string-requestgetresponseheaderheader","text":"The value of the given response header, if the request has been responded to (see respond ).","title":"String request.getResponseHeader(header);"},{"location":"#object-requestgetallresponseheaders","text":"All response headers as an object.","title":"Object request.getAllResponseHeaders();"},{"location":"#filtered-requests","text":"When using Sinon.JS for mockups or partial integration/functional testing, you might want to fake some requests, while allowing others to go through to the backend server. With filtered FakeXMLHttpRequest s (new in v1.3.0), you can.","title":"Filtered requests"},{"location":"#fakexmlhttprequestusefilters","text":"Default false . When set to true , Sinon will check added filters if certain requests should be \"unfaked\"","title":"FakeXMLHttpRequest.useFilters"},{"location":"#fakexmlhttprequestaddfilterfn","text":"Add a filter that will decide whether or not to fake a request. The filter will be called when xhr.open is called, with the exact same arguments ( method , url , async , username , password ). If the filter returns true , the request will not be faked.","title":"FakeXMLHttpRequest.addFilter(fn)"},{"location":"#simulating-server-responses","text":"","title":"Simulating server responses"},{"location":"#requestsetstatusstatus","text":"Sets response status ( status and statusText properties). Status should be a number, the status text is looked up from fakeXhr.FakeXMLHttpRequest.statusCodes .","title":"request.setStatus(status);"},{"location":"#requestsetresponseheadersobject","text":"Sets response headers (e.g. { \"Content-Type\": \"text/html\", /* ... */ } , updates the readyState property and fires onreadystatechange .","title":"request.setResponseHeaders(object);"},{"location":"#requestsetresponsebodybody","text":"Sets the respond body, updates the readyState property and fires onreadystatechange . Additionally, populates responseXML with a parsed document if response headers indicate as much .","title":"request.setResponseBody(body);"},{"location":"#requestrespondstatus-headers-body","text":"Calls the above three methods.","title":"request.respond(status, headers, body);"},{"location":"#requesterror","text":"Simulates a network error on the request. The onerror handler will be called and the status will be 0 .","title":"request.error();"},{"location":"#boolean-requestautorespond","text":"When set to true , causes the server to automatically respond to incoming requests after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests.","title":"Boolean request.autoRespond"},{"location":"#number-requestautorespondafter","text":"When autoRespond is true , respond to requests after this number of milliseconds. Default is 10.","title":"Number request.autoRespondAfter"},{"location":"#fake-server","text":"High-level API to manipulate FakeXMLHttpRequest instances. For help with handling JSON-P please refer to our notes below var fakeServer = require(\"nise\").fakeServer; var sinon = require(\"sinon\"); { setUp: function () { this.server = 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\" }]); assert(server.requests.length > 0) } }","title":"Fake server"},{"location":"#var-server-fakeservercreateconfig","text":"Creates a new server. This function also calls useFakeXMLHttpRequest() . create accepts optional properties to configure the fake server. See options below for configuration parameters.","title":"var server = fakeServer.create([config]);"},{"location":"#var-server-fakeserverwithclockcreate","text":"Creates a server that also manages fake timers . This is useful when testing XHR objects created with e.g. jQuery 1.3.x, which uses a timer to poll the object for completion, rather than the usual onreadystatechange .","title":"var server = fakeServerWithClock.create();"},{"location":"#serverconfigureconfig","text":"Configures the fake server. See options below for configuration parameters.","title":"server.configure(config);"},{"location":"#serverrespondwithresponse","text":"Causes the server to respond to any request not matched by another response with the provided data. The default catch-all response is [404, {}, \"\"] . response can be one of three things: A String or ArrayBuffer representing the response body An Array with status, headers and response body, e.g. [200, { \"Content-Type\": \"text/html\", \"Content-Length\": 2 }, \"OK\"] A Function . Default status is 200 and default headers are none. When the response is a Function , it will be passed the request object. You must manually call respond on it to complete the request.","title":"server.respondWith(response);"},{"location":"#serverrespondwithurl-response","text":"Responds to all requests to given URL, e.g. /posts/1 .","title":"server.respondWith(url, response);"},{"location":"#serverrespondwithmethod-url-response","text":"Responds to all method requests to the given URL with the given response. method is an HTTP verb.","title":"server.respondWith(method, url, response);"},{"location":"#serverrespondwithurlregexp-response","text":"URL may be a regular expression, e.g. /\\\\/post\\\\//\\\\d+ If the response is a Function , it will be passed any capture groups from the regular expression along with the XMLHttpRequest object: server.respondWith(/\\/todo-items\\/(\\d+)/, function (xhr, id) { xhr.respond( 200, { \"Content-Type\": \"application/json\" }, '[{ \"id\": ' + id + \" }]\", ); });","title":"server.respondWith(urlRegExp, response);"},{"location":"#serverrespondwithmethod-urlregexp-response","text":"Responds to all method requests to URLs matching the regular expression.","title":"server.respondWith(method, urlRegExp, response);"},{"location":"#serverrespond","text":"Causes all queued asynchronous requests to receive a response. If none of the responses added through respondWith match, the default response is [404, {}, \"\"] . Synchronous requests are responded to immediately, so make sure to call respondWith upfront. If called with arguments, respondWith will be called with those arguments before responding to requests.","title":"server.respond();"},{"location":"#serverautorespond-true","text":"If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead.","title":"server.autoRespond = true;"},{"location":"#serverautorespondafter-ms","text":"Causes the server to automatically respond to incoming requests after a timeout.","title":"server.autoRespondAfter = ms;"},{"location":"#serverrespondimmediately-true","text":"If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter .","title":"server.respondImmediately = true;"},{"location":"#array-serverrequests","text":"You can inspect the server.requests to verify request ordering, find unmatched requests or check that no requests has been done. server.requests is an array of all the FakeXMLHttpRequest objects that have been created.","title":"array server.requests"},{"location":"#boolean-serverfakehttpmethods","text":"If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request) .","title":"Boolean server.fakeHTTPMethods"},{"location":"#servergethttpmethodrequest","text":"Used internally to determine the HTTP method used with the provided request. By default this method simply returns request.method . When server.fakeHTTPMethods is true, the method will return the value of the _method parameter if the method is \"POST\". This method can be overridden to provide custom behavior.","title":"server.getHTTPMethod(request)"},{"location":"#serverrestore","text":"Restores the native XHR constructor.","title":"server.restore();"},{"location":"#fake-server-options","text":"These options are properties on the server object and can be set directly server.autoRespond = true; You can also pass options with an object literal to fakeServer.create and .configure .","title":"Fake server options"},{"location":"#boolean-autorespond","text":"If set, will automatically respond to every request after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests. For synchronous immediate responses, use respondImmediately instead.","title":"Boolean autoRespond"},{"location":"#number-autorespondafter-ms","text":"Causes the server to automatically respond to incoming requests after a timeout.","title":"Number autoRespondAfter (ms)"},{"location":"#boolean-respondimmediately","text":"If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter .","title":"Boolean respondImmediately"},{"location":"#boolean-fakehttpmethods","text":"If set to true , server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request)","title":"boolean fakeHTTPMethods"}]} \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index 78c3da2..8e64dee 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,7 +2,7 @@ None - 2024-09-10 + 2024-09-12 daily \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 5144465ac70e41d0b63e269b841609f75b323b1c..182bdf4ea65a9a50dff867ebd215e556fdd9fa1e 100644 GIT binary patch literal 189 zcmV;u07CyCiwFn=bmL|M|8r?{Wo=<_E_iKh08LK25`!QR?EMOcUQV49F@xBpOqF~9 zgG8A@FdT`=-v=Ls+uYvX&hGK{J6iJ50gZPJEm=W{cFK3g^$mU8ulbp_BIEC1QAd)@ z4jVeeI9&kdd1h#$9_570haON3X+hXUC|FHJMiQ2QjjiC;D{=Eqb6D8%ATf@<6ID^2 r@}kbmDp_{zU{iy1y?zG$5}h>m$KjxCjj&d(BfT#EIG_47>Hq)$|9V+p literal 189 zcmV;u07CyCiwFpQQs8C+|8r?{Wo=<_E_iKh08LK25`!QR?EMOcUJjiUF@xBpOqF~9 zgG8B8FdT`=-v=Ls+uYvX&hClkI}YSy0$T5CS};zDaoV@mbv1q5ulboaG86AGpot`z z9oDpuak>D^^UTmjGpY%h4;`TH(}J*zz*$9QMiQ2Qjja%a*Yf6_5wNi1L17$yD@$IU ra$e;HPnKOf*mSR4XP&{lWUK7(6L3(rMp!G?kzSX7Q9hls>Hq)$IeA$`