mockxhr
v2.3.0
Published
Flyweight ajax and mock-ajax with zero dependency.
Downloads
31
Readme
mockxhr
Flyweight ajax and mock-ajax with zero dependency.
Installation
npm install --save mockxhr
API
See index.d.ts
Usage
mockxhr.GET("https://api.github.com/users/wizawu", {}, function(resp) {
// normal ajax
console.log(resp)
})
// start mocking
mockxhr.setMock(true)
mockxhr.mock("GET", "https://api.github.com/users/wizawu", function(req) {
return { login: req.name }
})
mockxhr.GET("https://api.github.com/users/wizawu", { name: "a" }, function(resp) {
// { "login": "a" }
console.log(resp)
})
mockxhr.mock("GET", "/users/.*", function(req) {
return { login: req.name }
})
mockxhr.GET("/users/wizawu", { name: "b" }, function(resp) {
// { "login": "b" }
console.log(resp)
})