You can tell Y.IO
to use a custom transport other than the default XMLRequestObject
. There may be other ways to add custom transports to Y.IO
, but this worked for me:
Create a function that monkey patches a custom transport mode, mock, to Y.IO
:
function _createMockTransport(mockXHR) {
Y.IO.transports.mock = function () {
return mockXHR;
}
}
Then, in your setup function, add a variant of the following:
// I change the Y.IO instantiation configuration when instantiating my application
this.application = new Application({ yIOConfig: { xdr: { use: 'mock' }}})
this.xhr = Y.Mock();
Y.Mock.expect(this.xhr, {
method: 'send',
args: [Y.Mock.Value.Object, '/foo', Y.Mock.Value.Object]
});
_createMockTransport(this.xhr);
A example test would look like this:
"test /foo": function () {
this.appliation.doServerCall();
Y.Mock.verify(this.xhr);
},