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 REJECTED = 4
|
||||
|
||||
function coerce(value, next, error, inst) {
|
||||
function coerce(value, next, error) {
|
||||
if (isPromise(value)) {
|
||||
return value.then(function (value) {
|
||||
coerce(value, next, error, inst)
|
||||
coerce(value, next, error)
|
||||
}, function (e) {
|
||||
coerce(e, error, error, inst)
|
||||
coerce(e, error, error)
|
||||
})
|
||||
} 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() {
|
||||
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.$headers[key] = value
|
||||
}
|
||||
|
|
@ -237,9 +246,6 @@ this.mock = (function (global) {
|
|||
}
|
||||
|
||||
this.send = function () {
|
||||
this.responseText = JSON.stringify(this)
|
||||
this.readyState = 4
|
||||
this.status = 200
|
||||
Request.$instances.push(this)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -648,7 +648,7 @@ describe("m.mount()", function () {
|
|||
})
|
||||
|
||||
function resolveXhr() {
|
||||
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
||||
mock.XMLHttpRequest.$instances.pop().$resolve()
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ describe("m.request()", function () {
|
|||
// Much easier to read
|
||||
function resolve() {
|
||||
var xhr = mock.XMLHttpRequest.$instances.pop()
|
||||
xhr.onreadystatechange()
|
||||
xhr.$resolve.apply(xhr, arguments)
|
||||
return xhr
|
||||
}
|
||||
|
||||
|
|
@ -181,8 +181,7 @@ describe("m.request()", function () {
|
|||
data: {foo: 1}
|
||||
}).then(null, error)
|
||||
|
||||
var xhr = mock.XMLHttpRequest.$instances.pop()
|
||||
xhr.onreadystatechange()
|
||||
var xhr = mock.XMLHttpRequest.$instances.pop().$resolve()
|
||||
|
||||
expect(xhr.$headers).to.have.property(
|
||||
"Content-Type",
|
||||
|
|
@ -197,8 +196,7 @@ describe("m.request()", function () {
|
|||
url: "test"
|
||||
}).then(null, error)
|
||||
|
||||
var xhr = mock.XMLHttpRequest.$instances.pop()
|
||||
xhr.onreadystatechange()
|
||||
var xhr = mock.XMLHttpRequest.$instances.pop().$resolve()
|
||||
|
||||
expect(xhr.$headers).to.not.have.property("Content-Type")
|
||||
})
|
||||
|
|
@ -381,4 +379,21 @@ describe("m.request()", function () {
|
|||
// For good measure
|
||||
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