Fix inflexible/slightly broken m.request tests

This commit is contained in:
impinball 2015-12-16 13:33:34 -05:00
parent 7f7a0a3815
commit c21566366e
3 changed files with 27 additions and 4 deletions

View file

@ -648,7 +648,7 @@ describe("m.mount()", function () {
})
function resolveXhr() {
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
mock.XMLHttpRequest.$instances.pop().$resolve().onreadystatechange()
mock.requestAnimationFrame.$resolve()
}

View file

@ -4,6 +4,7 @@ describe("m.request()", function () {
// Much easier to read
function resolve() {
var xhr = mock.XMLHttpRequest.$instances.pop()
xhr.$resolve.apply(xhr, arguments)
xhr.onreadystatechange()
return xhr
}
@ -381,4 +382,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
})
})