diff --git a/app/assets/javascripts/labels_select.js b/app/assets/javascripts/labels_select.js
index d479f7ed6824a73a9077c9edcedbba9305f42653..84602cf92076fea7b375ad1a9660d95fef08fa3b 100644
--- a/app/assets/javascripts/labels_select.js
+++ b/app/assets/javascripts/labels_select.js
@@ -285,7 +285,7 @@ import CreateLabelDropdown from './create_label';
           },
           hidden: function() {
             var isIssueIndex, isMRIndex, page, selectedLabels;
-            page = $('body').data('page');
+            page = $('body').attr('data-page');
             isIssueIndex = page === 'projects:issues:index';
             isMRIndex = page === 'projects:merge_requests:index';
             $selectbox.hide();
@@ -325,7 +325,7 @@ import CreateLabelDropdown from './create_label';
               $loading.fadeOut();
             };
 
-            page = $('body').data('page');
+            page = $('body').attr('data-page');
             isIssueIndex = page === 'projects:issues:index';
             isMRIndex = page === 'projects:merge_requests:index';
 
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 423a25fbdfab8688283587d10e40a71aa5778054..9f05cf16967e867cea90831846f94df7652b0524 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -1,5 +1,5 @@
 
-export const getPagePath = (index = 0) => $('body').data('page').split(':')[index];
+export const getPagePath = (index = 0) => $('body').attr('data-page').split(':')[index];
 
 export const isInGroupsPage = () => getPagePath() === 'groups';
 
diff --git a/app/assets/javascripts/milestone_select.js b/app/assets/javascripts/milestone_select.js
index eed89fd6347ec6a4f64b03bc0998603bb269b5a2..ad04d75f32c9e12d0bc297bfbd63f23c069a4ef2 100644
--- a/app/assets/javascripts/milestone_select.js
+++ b/app/assets/javascripts/milestone_select.js
@@ -170,7 +170,7 @@ import _ from 'underscore';
 
             var data, isIssueIndex, isMRIndex, isSelecting, page, boardsStore;
             if (!selected) return;
-            page = $('body').data('page');
+            page = $('body').attr('data-page');
             isIssueIndex = page === 'projects:issues:index';
             isMRIndex = (page === page && page === 'projects:merge_requests:index');
             isSelecting = (selected.name !== selectedMilestone);
diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js
index cf7322ba1da6ead26025e9b1cedae9ae24887352..a40a6e297433a741bdca0e10254c3c5791391004 100644
--- a/app/assets/javascripts/notes.js
+++ b/app/assets/javascripts/notes.js
@@ -1257,7 +1257,7 @@ export default class Notes {
   }
 
   static checkMergeRequestStatus() {
-    if (getPagePath(1) === 'merge_requests') {
+    if (getPagePath(1) === 'merge_requests' && gl.mrWidget) {
       gl.mrWidget.checkStatus();
     }
   }
diff --git a/app/assets/javascripts/users_select.js b/app/assets/javascripts/users_select.js
index 73676bd6de7c5923787cae686d1cae76d86f13a2..a0883b32593bf6c4213f979752814bb2e1321a96 100644
--- a/app/assets/javascripts/users_select.js
+++ b/app/assets/javascripts/users_select.js
@@ -424,7 +424,7 @@ function UsersSelect(currentUser, els) {
           }
 
           var isIssueIndex, isMRIndex, page, selected;
-          page = $('body').data('page');
+          page = $('body').attr('data-page');
           isIssueIndex = page === 'projects:issues:index';
           isMRIndex = (page === page && page === 'projects:merge_requests:index');
           if ($dropdown.hasClass('js-filter-bulk-update') || $dropdown.hasClass('js-issuable-form-dropdown')) {
diff --git a/changelogs/unreleased/38871-cleanup-data-page-attribute-after-karma-test.yml b/changelogs/unreleased/38871-cleanup-data-page-attribute-after-karma-test.yml
new file mode 100644
index 0000000000000000000000000000000000000000..5e142a2b4cfe257b2a2375a97a175974d6507d42
--- /dev/null
+++ b/changelogs/unreleased/38871-cleanup-data-page-attribute-after-karma-test.yml
@@ -0,0 +1,5 @@
+---
+title: Cleanup data-page attribute after each Karma test
+merge_request: 14742
+author:
+type: fixed
diff --git a/spec/javascripts/awards_handler_spec.js b/spec/javascripts/awards_handler_spec.js
index a22b71fd1dcf0ce89e71838066bc02bb8f7b0160..268b5b83b730a735c818b4f8353daabe23a391e4 100644
--- a/spec/javascripts/awards_handler_spec.js
+++ b/spec/javascripts/awards_handler_spec.js
@@ -28,7 +28,7 @@ import '~/lib/utils/common_utils';
     preloadFixtures('merge_requests/diff_comment.html.raw');
     beforeEach(function(done) {
       loadFixtures('merge_requests/diff_comment.html.raw');
-      $('body').data('page', 'projects:merge_requests:show');
+      $('body').attr('data-page', 'projects:merge_requests:show');
       loadAwardsHandler(true).then((obj) => {
         awardsHandler = obj;
         spyOn(awardsHandler, 'postEmoji').and.callFake((button, url, emoji, cb) => cb());
@@ -55,6 +55,9 @@ import '~/lib/utils/common_utils';
       // restore original url root value
       gon.relative_url_root = urlRoot;
 
+      // Undo what we did to the shared <body>
+      $('body').removeAttr('data-page');
+
       awardsHandler.destroy();
     });
     describe('::showEmojiMenu', function() {
diff --git a/spec/javascripts/behaviors/quick_submit_spec.js b/spec/javascripts/behaviors/quick_submit_spec.js
index f62bf43adb9f5b6abaa6daaceed44eb3bc4d1073..d5300d9c63dd2d50f6a8db56d049d2ab79999941 100644
--- a/spec/javascripts/behaviors/quick_submit_spec.js
+++ b/spec/javascripts/behaviors/quick_submit_spec.js
@@ -19,6 +19,11 @@ describe('Quick Submit behavior', () => {
     this.textarea = $('.js-quick-submit textarea').first();
   });
 
+  afterEach(() => {
+    // Undo what we did to the shared <body>
+    $('body').removeAttr('data-page');
+  });
+
   it('does not respond to other keyCodes', () => {
     this.textarea.trigger(keydownEvent({
       keyCode: 32,
diff --git a/spec/javascripts/merge_request_notes_spec.js b/spec/javascripts/merge_request_notes_spec.js
index 395dc560671e5872526f1895dc845bb945f8669d..ac6ace48108f2479be565bf59d1c828041eb71dd 100644
--- a/spec/javascripts/merge_request_notes_spec.js
+++ b/spec/javascripts/merge_request_notes_spec.js
@@ -23,12 +23,17 @@ describe('Merge request notes', () => {
       loadFixtures(discussionTabFixture);
       gl.utils.disableButtonIfEmptyField = _.noop;
       window.project_uploads_path = 'http://test.host/uploads';
-      $('body').data('page', 'projects:merge_requests:show');
+      $('body').attr('data-page', 'projects:merge_requests:show');
       window.gon.current_user_id = $('.note:last').data('author-id');
 
       return new Notes('', []);
     });
 
+    afterEach(() => {
+      // Undo what we did to the shared <body>
+      $('body').removeAttr('data-page');
+    });
+
     describe('up arrow', () => {
       it('edits last comment when triggered in main form', () => {
         const upArrowEvent = $.Event('keydown');
@@ -71,12 +76,17 @@ describe('Merge request notes', () => {
         <textarea class="js-note-text"></textarea>
       </form>`;
       setFixtures(diffsResponse.html + noteFormHtml);
-      $('body').data('page', 'projects:merge_requests:show');
+      $('body').attr('data-page', 'projects:merge_requests:show');
       window.gon.current_user_id = $('.note:last').data('author-id');
 
       return new Notes('', []);
     });
 
+    afterEach(() => {
+      // Undo what we did to the shared <body>
+      $('body').removeAttr('data-page');
+    });
+
     describe('up arrow', () => {
       it('edits last comment in discussion when triggered in discussion form', (done) => {
         const upArrowEvent = $.Event('keydown');
diff --git a/spec/javascripts/merge_request_tabs_spec.js b/spec/javascripts/merge_request_tabs_spec.js
index ccdbfcba692661da552add735fdfbc61a51f8be9..18916c5aa97f5bbe87ac5eea5e6b9127ce5ebc32 100644
--- a/spec/javascripts/merge_request_tabs_spec.js
+++ b/spec/javascripts/merge_request_tabs_spec.js
@@ -277,7 +277,7 @@ import 'vendor/jquery.scrollTo';
     describe('loadDiff', function () {
       beforeEach(() => {
         loadFixtures('merge_requests/diff_comment.html.raw');
-        spyOn(window.gl.utils, 'getPagePath').and.returnValue('merge_requests');
+        $('body').attr('data-page', 'projects:merge_requests:show');
         window.gl.ImageFile = () => {};
         window.notes = new Notes('', []);
         spyOn(window.notes, 'toggleDiffNote').and.callThrough();
@@ -286,6 +286,9 @@ import 'vendor/jquery.scrollTo';
       afterEach(() => {
         delete window.gl.ImageFile;
         delete window.notes;
+
+        // Undo what we did to the shared <body>
+        $('body').removeAttr('data-page');
       });
 
       it('requires an absolute pathname', function () {
diff --git a/spec/javascripts/notes_spec.js b/spec/javascripts/notes_spec.js
index 65d2e8fd9fb4726575befd561d10f5f87c050a4d..34a49bee3f54e6535db5b6e19a90d9bf21720327 100644
--- a/spec/javascripts/notes_spec.js
+++ b/spec/javascripts/notes_spec.js
@@ -39,7 +39,12 @@ import '~/notes';
       loadFixtures(commentsTemplate);
       gl.utils.disableButtonIfEmptyField = _.noop;
       window.project_uploads_path = 'http://test.host/uploads';
-      $('body').data('page', 'projects:merge_requets:show');
+      $('body').attr('data-page', 'projects:merge_requets:show');
+    });
+
+    afterEach(() => {
+      // Undo what we did to the shared <body>
+      $('body').removeAttr('data-page');
     });
 
     describe('task lists', function() {
diff --git a/spec/javascripts/search_autocomplete_spec.js b/spec/javascripts/search_autocomplete_spec.js
index a53f58b5d0d250c24b416924526c56ff52eff674..cf811af3d6c1e674cff04f2542b32003c92314ec 100644
--- a/spec/javascripts/search_autocomplete_spec.js
+++ b/spec/javascripts/search_autocomplete_spec.js
@@ -6,7 +6,7 @@ import '~/lib/utils/common_utils';
 import 'vendor/fuzzaldrin-plus';
 
 (function() {
-  var addBodyAttributes, assertLinks, dashboardIssuesPath, dashboardMRsPath, groupIssuesPath, groupMRsPath, groupName, mockDashboardOptions, mockGroupOptions, mockProjectOptions, projectIssuesPath, projectMRsPath, projectName, userId, widget;
+  var assertLinks, dashboardIssuesPath, dashboardMRsPath, groupIssuesPath, groupMRsPath, groupName, mockDashboardOptions, mockGroupOptions, mockProjectOptions, projectIssuesPath, projectMRsPath, projectName, userId, widget;
   var userName = 'root';
 
   widget = null;
@@ -29,25 +29,31 @@ import 'vendor/fuzzaldrin-plus';
 
   groupName = 'Gitlab Org';
 
+  const removeBodyAttributes = function() {
+    const $body = $('body');
+
+    $body.removeAttr('data-page');
+    $body.removeAttr('data-project');
+    $body.removeAttr('data-group');
+  };
+
   // Add required attributes to body before starting the test.
   // section would be dashboard|group|project
-  addBodyAttributes = function(section) {
-    var $body;
+  const addBodyAttributes = function(section) {
     if (section == null) {
       section = 'dashboard';
     }
-    $body = $('body');
-    $body.removeAttr('data-page');
-    $body.removeAttr('data-project');
-    $body.removeAttr('data-group');
+
+    const $body = $('body');
+    removeBodyAttributes();
     switch (section) {
       case 'dashboard':
-        return $body.data('page', 'root:index');
+        return $body.attr('data-page', 'root:index');
       case 'group':
-        $body.data('page', 'groups:show');
+        $body.attr('data-page', 'groups:show');
         return $body.data('group', 'gitlab-org');
       case 'project':
-        $body.data('page', 'projects:show');
+        $body.attr('data-page', 'projects:show');
         return $body.data('project', 'gitlab-ce');
     }
   };
@@ -108,7 +114,7 @@ import 'vendor/fuzzaldrin-plus';
     preloadFixtures('static/search_autocomplete.html.raw');
     beforeEach(function() {
       loadFixtures('static/search_autocomplete.html.raw');
-      widget = new gl.SearchAutocomplete;
+
       // Prevent turbolinks from triggering within gl_dropdown
       spyOn(window.gl.utils, 'visitUrl').and.returnValue(true);
 
@@ -120,6 +126,8 @@ import 'vendor/fuzzaldrin-plus';
     });
 
     afterEach(function() {
+      // Undo what we did to the shared <body>
+      removeBodyAttributes();
       window.gon = {};
     });
     it('should show Dashboard specific dropdown menu', function() {