From 56ef83fa8aaad0752b1c73311ba46c5c8321cb42 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Sun, 2 Jan 2022 17:09:16 -0800 Subject: [PATCH] Don't overwrite app.stream properties in tests These cases of modifying app.stream can cause other specs to fail, depending on test order. Here we either don't modify them if the tests still pass without manually stubbing `addNow`, or we cache and restore the properties we need to test. --- .../javascripts/app/models/post/interacations_spec.js | 11 +++++++++-- spec/javascripts/app/views/publisher_view_spec.js | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spec/javascripts/app/models/post/interacations_spec.js b/spec/javascripts/app/models/post/interacations_spec.js index 599929eca..5e318b4e3 100644 --- a/spec/javascripts/app/models/post/interacations_spec.js +++ b/spec/javascripts/app/models/post/interacations_spec.js @@ -122,9 +122,11 @@ describe("app.models.Post.Interactions", function(){ }); it("adds the reshare to the default, activity and aspects stream", function() { - app.stream = { addNow: $.noop }; + app.stream = new app.models.Stream(_, { basePath: "/aspects/all" }); + spyOn(app.stream, "addNow"); var self = this; + ["/stream", "/activity", "/aspects"].forEach(function(path) { app.stream.basePath = function() { return path; }; self.interactions.reshare(); @@ -132,10 +134,13 @@ describe("app.models.Post.Interactions", function(){ expect(app.stream.addNow).toHaveBeenCalledWith({id: 1}); }); + + new app.models.Stream(_, { basePath: "/aspects/all" }); }); it("doesn't add the reshare to any other stream", function() { - app.stream = { addNow: $.noop }; + app.stream = new app.models.Stream(_, { basePath: "/aspects/all" }); + spyOn(app.stream, "addNow"); var self = this; ["/followed_tags", "/mentions/", "/tag/diaspora", "/people/guid/stream"].forEach(function(path) { @@ -144,6 +149,8 @@ describe("app.models.Post.Interactions", function(){ jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess); expect(app.stream.addNow).not.toHaveBeenCalled(); }); + + new app.models.Stream(_, { basePath: "/aspects/all" }); }); it("sets the participation flag for the post", function() { diff --git a/spec/javascripts/app/views/publisher_view_spec.js b/spec/javascripts/app/views/publisher_view_spec.js index a43d12a76..305e547e0 100644 --- a/spec/javascripts/app/views/publisher_view_spec.js +++ b/spec/javascripts/app/views/publisher_view_spec.js @@ -25,7 +25,8 @@ describe("app.views.Publisher", function() { describe("createStatusMessage", function(){ it("doesn't add the status message to the stream", function() { - app.stream = { addNow: $.noop }; + app.stream = new app.models.Stream(); + spyOn(app.stream, "addNow"); this.view.createStatusMessage($.Event()); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, responseText: "{\"id\": 1}" }); @@ -198,7 +199,8 @@ describe("app.views.Publisher", function() { describe("createStatusMessage", function(){ it("adds the status message to the stream", function() { - app.stream = { addNow: $.noop }; + new app.models.Stream(); + spyOn(app.stream, "addNow"); this.view.createStatusMessage($.Event()); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, responseText: "{\"id\": 1}" });