diff --git a/app/assets/javascripts/discourse/app/lib/ajax.js b/app/assets/javascripts/discourse/app/lib/ajax.js index 2bdeb0459ea..45059a60750 100644 --- a/app/assets/javascripts/discourse/app/lib/ajax.js +++ b/app/assets/javascripts/discourse/app/lib/ajax.js @@ -119,9 +119,14 @@ export function ajax() { args.error = (xhr, textStatus, errorThrown) => { // 0 represents the `UNSENT` state - if (xhr.readyState === 0 && !isTesting()) { + if (xhr.readyState === 0) { + // Make sure we log pretender errors in test mode + if (isTesting()) { + throw errorThrown; + } return; } + handleLogoff(xhr); // note: for bad CSRF we don't loop an extra request right away. diff --git a/test/javascripts/acceptance/composer-test.js b/test/javascripts/acceptance/composer-test.js index 235236a2d2a..de47599dad0 100644 --- a/test/javascripts/acceptance/composer-test.js +++ b/test/javascripts/acceptance/composer-test.js @@ -859,10 +859,6 @@ QUnit.test("can reply to a private message", async assert => { return [200, { "Content-Type": "application/json" }, {}]; }); - // a bit messy but we need a fake here cause we issue a route transition - // to the new post - server.get("/t/34/4.json", () => server.get("/t/34.json")); - await visit("/t/34"); await click(".topic-post:eq(0) button.reply"); await fillIn(".d-editor-input", "this is the *content* of the reply"); diff --git a/test/javascripts/helpers/create-pretender.js b/test/javascripts/helpers/create-pretender.js index 371e6517752..1ed9e4c4b05 100644 --- a/test/javascripts/helpers/create-pretender.js +++ b/test/javascripts/helpers/create-pretender.js @@ -2,20 +2,22 @@ import User from "discourse/models/user"; export function parsePostData(query) { const result = {}; - query.split("&").forEach(function(part) { - const item = part.split("="); - const firstSeg = decodeURIComponent(item[0]); - const m = /^([^\[]+)\[(.+)\]/.exec(firstSeg); + if (query) { + query.split("&").forEach(function(part) { + const item = part.split("="); + const firstSeg = decodeURIComponent(item[0]); + const m = /^([^\[]+)\[(.+)\]/.exec(firstSeg); - const val = decodeURIComponent(item[1]).replace(/\+/g, " "); - if (m) { - let key = m[1]; - result[key] = result[key] || {}; - result[key][m[2].replace("][", ".")] = val; - } else { - result[firstSeg] = val; - } - }); + const val = decodeURIComponent(item[1]).replace(/\+/g, " "); + if (m) { + let key = m[1]; + result[key] = result[key] || {}; + result[key][m[2].replace("][", ".")] = val; + } else { + result[firstSeg] = val; + } + }); + } return result; } @@ -245,6 +247,7 @@ export function applyDefaultHandlers(pretender) { pretender.get("/t/280.json", () => response(fixturesByUrl["/t/280/1.json"])); pretender.get("/t/34.json", () => response(fixturesByUrl["/t/34/1.json"])); + pretender.get("/t/34/4.json", () => response(fixturesByUrl["/t/34/1.json"])); pretender.get("/t/280/:post_number.json", () => response(fixturesByUrl["/t/280/1.json"]) ); @@ -255,7 +258,9 @@ export function applyDefaultHandlers(pretender) { pretender.get("/t/12.json", () => response(fixturesByUrl["/t/12/1.json"])); pretender.put("/t/1234/re-pin", success); - pretender.get("/t/2480.json", () => response(fixturesByUrl["/t/2480/1.json"])); + pretender.get("/t/2480.json", () => + response(fixturesByUrl["/t/2480/1.json"]) + ); pretender.get("/t/id_for/:slug", () => { return response({ diff --git a/test/javascripts/models/user-badge-test.js b/test/javascripts/models/user-badge-test.js index 80d2432453b..870a8ad8fbe 100644 --- a/test/javascripts/models/user-badge-test.js +++ b/test/javascripts/models/user-badge-test.js @@ -4,7 +4,9 @@ import badgeFixtures from "fixtures/user-badges"; QUnit.module("model:user-badge"); QUnit.test("createFromJson single", assert => { - const userBadge = UserBadge.createFromJson(badgeFixtures["/user_badges"]); + const userBadge = UserBadge.createFromJson( + JSON.parse(JSON.stringify(badgeFixtures["/user_badges"])) + ); assert.ok(!Array.isArray(userBadge), "does not return an array"); assert.equal( userBadge.get("badge.name"), @@ -25,7 +27,7 @@ QUnit.test("createFromJson single", assert => { QUnit.test("createFromJson array", assert => { const userBadges = UserBadge.createFromJson( - badgeFixtures["/user-badges/:username"] + JSON.parse(JSON.stringify(badgeFixtures["/user-badges/:username"])) ); assert.ok(Array.isArray(userBadges), "returns an array"); assert.equal(