Dart Documentationangular.mockMockHttpExpectation

MockHttpExpectation class

An internal class used by MockHttpBackend.

class MockHttpExpectation {

 var method, url, data, headers;

 var response;

 MockHttpExpectation(this.method, this.url, [this.data, this.headers]);

 match(m, u, [d, h]) {
   if (method != m) return false;
   if (!matchUrl(u)) return false;
   if (d != null && !matchData(d)) return false;
   if (h != null && !matchHeaders(h)) return false;
   return true;
 }

 matchUrl(u) {
   if (url == null) return true;
   if (url is RegExp) return url.hasMatch(u);
   return url == u;
 }

 matchHeaders(h) {
   if (headers == null) return true;
   if (headers is Function) return headers(h);
   return "$headers" == "$h";
 }

 matchData(d) {
   if (data == null) return true;
   if (d == null) return false; // data is not null, but d is.
   if (data is File) return data == d;
   assert(d is String);
   if (data is RegExp) return data.hasMatch(d);
   return json.stringify(data) == json.stringify(d);
 }

 toString() {
   return "$method $url";
 }
}

Constructors

new MockHttpExpectation(method, url, [data, headers]) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
MockHttpExpectation(this.method, this.url, [this.data, this.headers]);

Properties

var data #

var method, url, data

var headers #

var method, url, data, headers

var method #

var method

var response #

var response

var url #

var method, url

Methods

dynamic match(m, u, [d, h]) #

match(m, u, [d, h]) {
 if (method != m) return false;
 if (!matchUrl(u)) return false;
 if (d != null && !matchData(d)) return false;
 if (h != null && !matchHeaders(h)) return false;
 return true;
}

dynamic matchData(d) #

matchData(d) {
 if (data == null) return true;
 if (d == null) return false; // data is not null, but d is.
 if (data is File) return data == d;
 assert(d is String);
 if (data is RegExp) return data.hasMatch(d);
 return json.stringify(data) == json.stringify(d);
}

dynamic matchHeaders(h) #

matchHeaders(h) {
 if (headers == null) return true;
 if (headers is Function) return headers(h);
 return "$headers" == "$h";
}

dynamic matchUrl(u) #

matchUrl(u) {
 if (url == null) return true;
 if (url is RegExp) return url.hasMatch(u);
 return url == u;
}

dynamic toString() #

Returns a string representation of this object.

docs inherited from Object
toString() {
 return "$method $url";
}