Merge pull request #897 from isiahmeadows/deferred-fix
Clean up unused parameter and m.request tests
This commit is contained in:
commit
49b97a5e56
6 changed files with 36 additions and 15 deletions
|
|
@ -1859,15 +1859,15 @@
|
||||||
var RESOLVED = 3
|
var RESOLVED = 3
|
||||||
var REJECTED = 4
|
var REJECTED = 4
|
||||||
|
|
||||||
function coerce(value, next, error, inst) {
|
function coerce(value, next, error) {
|
||||||
if (isPromise(value)) {
|
if (isPromise(value)) {
|
||||||
return value.then(function (value) {
|
return value.then(function (value) {
|
||||||
coerce(value, next, error, inst)
|
coerce(value, next, error)
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
coerce(e, error, error, inst)
|
coerce(e, error, error)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return next.call(inst, value)
|
return next(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
mithril.min.js
vendored
2
mithril.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -227,6 +227,15 @@ this.mock = (function (global) {
|
||||||
function Request() {
|
function Request() {
|
||||||
this.$headers = {}
|
this.$headers = {}
|
||||||
|
|
||||||
|
this.$resolve = function (data, status) {
|
||||||
|
if (data === undefined) data = this // eslint-disable-line
|
||||||
|
this.responseText = JSON.stringify(data)
|
||||||
|
this.readyState = 4
|
||||||
|
this.status = status || 200
|
||||||
|
this.onreadystatechange()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
this.setRequestHeader = function (key, value) {
|
this.setRequestHeader = function (key, value) {
|
||||||
this.$headers[key] = value
|
this.$headers[key] = value
|
||||||
}
|
}
|
||||||
|
|
@ -237,9 +246,6 @@ this.mock = (function (global) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send = function () {
|
this.send = function () {
|
||||||
this.responseText = JSON.stringify(this)
|
|
||||||
this.readyState = 4
|
|
||||||
this.status = 200
|
|
||||||
Request.$instances.push(this)
|
Request.$instances.push(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -648,7 +648,7 @@ describe("m.mount()", function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
function resolveXhr() {
|
function resolveXhr() {
|
||||||
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
mock.XMLHttpRequest.$instances.pop().$resolve()
|
||||||
mock.requestAnimationFrame.$resolve()
|
mock.requestAnimationFrame.$resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ describe("m.request()", function () {
|
||||||
// Much easier to read
|
// Much easier to read
|
||||||
function resolve() {
|
function resolve() {
|
||||||
var xhr = mock.XMLHttpRequest.$instances.pop()
|
var xhr = mock.XMLHttpRequest.$instances.pop()
|
||||||
xhr.onreadystatechange()
|
xhr.$resolve.apply(xhr, arguments)
|
||||||
return xhr
|
return xhr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,8 +181,7 @@ describe("m.request()", function () {
|
||||||
data: {foo: 1}
|
data: {foo: 1}
|
||||||
}).then(null, error)
|
}).then(null, error)
|
||||||
|
|
||||||
var xhr = mock.XMLHttpRequest.$instances.pop()
|
var xhr = mock.XMLHttpRequest.$instances.pop().$resolve()
|
||||||
xhr.onreadystatechange()
|
|
||||||
|
|
||||||
expect(xhr.$headers).to.have.property(
|
expect(xhr.$headers).to.have.property(
|
||||||
"Content-Type",
|
"Content-Type",
|
||||||
|
|
@ -197,8 +196,7 @@ describe("m.request()", function () {
|
||||||
url: "test"
|
url: "test"
|
||||||
}).then(null, error)
|
}).then(null, error)
|
||||||
|
|
||||||
var xhr = mock.XMLHttpRequest.$instances.pop()
|
var xhr = mock.XMLHttpRequest.$instances.pop().$resolve()
|
||||||
xhr.onreadystatechange()
|
|
||||||
|
|
||||||
expect(xhr.$headers).to.not.have.property("Content-Type")
|
expect(xhr.$headers).to.not.have.property("Content-Type")
|
||||||
})
|
})
|
||||||
|
|
@ -381,4 +379,21 @@ describe("m.request()", function () {
|
||||||
// For good measure
|
// For good measure
|
||||||
mock.requestAnimationFrame.$resolve()
|
mock.requestAnimationFrame.$resolve()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can use a config correctly", function () {
|
||||||
|
var config = sinon.spy()
|
||||||
|
var result = m.prop()
|
||||||
|
var error = sinon.spy
|
||||||
|
var opts = {
|
||||||
|
method: "GET",
|
||||||
|
url: "/test",
|
||||||
|
config: config
|
||||||
|
}
|
||||||
|
m.request(opts).then(result, error)
|
||||||
|
var xhr = resolve({foo: "bar"})
|
||||||
|
|
||||||
|
expect(config).to.be.calledWithExactly(xhr, opts)
|
||||||
|
expect(result()).to.eql({foo: "bar"})
|
||||||
|
expect(error).to.not.be.called
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue