Module: alfresco/testing/MockXhr

alfresco/testing/MockXhr

This can be extended for creating widgets that provide Mock XHR responses. It is provided for use in testing and will replace the standard browser XMLHttpRequest rendering all standard XHR requests impossible when included on a page.
Since:
  • 1.0.50
Author:
  • Dave Draper
  • Martin Doyle
License:
Source:

Members

cssRequirements :object[]

An array of the CSS files to use with this widget.
Type:
  • object[]
Default Value:
  • [{cssFile:"./css/MockXhr.css"}]
Source:

respondAfter :number

An amount of time (in milliseconds) to respond after. This is useful for giving the test a chance to cancel operations. If no value is given then it will respond immediately.
Type:
  • number
Default Value:
  • null
Source:

templateString :string

The HTML template to use for the widget.
Type:
  • string
Source:

Methods

_clearLog()

Clear the log node
Source:

_onWidgetClick(evt)

This top-level click handler is to prevent click events on the log bubbling back up to the document.
Parameters:
Name Type Description
evt Event Dojo-normalised event object
Since:
  • 1.0.61
Source:

_toggleBody()

Toggle the body visibility for the log
Source:

buildBodyHTML(body) → {string}

Build the HTML for displaying a request/response body on the page
Parameters:
Name Type Description
body object The body object (request or response)
Source:
Returns:
The HTML
Type
string

buildHeadersHTML(headers) → {string}

Build the HTML for displaying headers on the page
Parameters:
Name Type Description
headers object The headers object (request or response)
Source:
Returns:
The HTML
Type
string

constructor()

Sets up the Sinon fake server.
Source:

loadBinaryData()

This is an extension point function intended to be overridden by extending mock xhr services. The extension should load binary data before the XMLHttpRequest object is overridden by Sinon and the data loading call backs should call the waitForServer function which will in turn call setupServerWithBinaryData when the fake Sinon server is ready for configuring.
Source:

setupServer()

This is an extension point function intended to be overridden by extending mock xhr services. It should be overridden to set up the fake server with all the responses it should provide.
Source:

setupServerWithBinaryData()

This is an extension point function intended to be overridden by extending mock xhr services. It is called from waitForServer and indicates that both the binary data and the fake Sinon server are ready to use.
Source:

updateLog(xhrRequest)

Adds the details of each XHR request to the log so that it can be queried by a unit test to check that services are making appropriate requests for data.
Parameters:
Name Type Description
xhrRequest object The XHR request that was made
Source:

waitForServer()

This should be called from loadBinaryData once binary data is loaded. It will call setupServerWithBinaryData once the fake Sinon server is ready to be configured to return the binary data.
Source: