diff --git a/test-deps/mock.js b/test-deps/mock.js index 698f86bc..81304cbe 100644 --- a/test-deps/mock.js +++ b/test-deps/mock.js @@ -227,6 +227,14 @@ 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 + return this + } + this.setRequestHeader = function (key, value) { this.$headers[key] = value } @@ -237,9 +245,6 @@ this.mock = (function (global) { } this.send = function () { - this.responseText = JSON.stringify(this) - this.readyState = 4 - this.status = 200 Request.$instances.push(this) } } diff --git a/test/mithril.mount.js b/test/mithril.mount.js index fa68d11f..d5f606d9 100644 --- a/test/mithril.mount.js +++ b/test/mithril.mount.js @@ -648,7 +648,7 @@ describe("m.mount()", function () { }) function resolveXhr() { - mock.XMLHttpRequest.$instances.pop().onreadystatechange() + mock.XMLHttpRequest.$instances.pop().$resolve().onreadystatechange() mock.requestAnimationFrame.$resolve() } diff --git a/test/mithril.request.js b/test/mithril.request.js index d432ab43..945164dc 100644 --- a/test/mithril.request.js +++ b/test/mithril.request.js @@ -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 + }) })