Skip to content

Commit 10a4ec2

Browse files
Backport PR elastic#8822
--------- **Commit 1:** [tests] ensure that the notifier is emptied by each test * Original sha: 11e9af0d765960bcf586bbebe2d9309b1506d264 [formerly 0cdef8c] * Authored by spalger <[email protected]> on 2016-10-25T00:09:57Z **Commit 2:** [testHarness] use generic Error class * Original sha: d7e994e720ebdb6a2c0cd499936956ad1fe1fbee [formerly 34659fb] * Authored by spalger <[email protected]> on 2016-10-25T22:11:39Z Former-commit-id: cfb469b
1 parent 1df6991 commit 10a4ec2

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/ui/public/notify/__tests__/notifier.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ describe('Notifier', function () {
3333

3434
beforeEach(function () {
3535
params = { location: 'foo' };
36-
while (Notifier.prototype._notifs.pop()); // clear global notifications
3736
notifier = new Notifier(params);
3837
});
3938

39+
afterEach(function () {
40+
Notifier.prototype._notifs.length = 0;
41+
});
42+
4043
describe('#constructor()', function () {
4144
it('sets #from from given location', function () {
4245
expect(notifier.from).to.equal(params.location);
@@ -465,13 +468,12 @@ describe('Directive Notification', function () {
465468
scope;
466469
});
467470

468-
while (Notifier.prototype._notifs.pop()); // clear global notifications
469-
470471
notifier = new Notifier({ location: 'directiveFoo' });
471472
directiveNotification = notifier.directive(directiveParam, customParams);
472473
});
473474

474475
afterEach(() => {
476+
Notifier.prototype._notifs.length = 0;
475477
directiveNotification.clear();
476478
scope.$destroy();
477479
});

src/ui/public/route_based_notifier/__tests__/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ describe('ui/route_based_notifier', function () {
1010

1111
beforeEach(ngMock.module('kibana'));
1212
beforeEach(ngMock.inject(($injector) => {
13-
remove(Notifier.prototype._notifs); // hack to reset the global notification array
1413
const Private = $injector.get('Private');
1514
routeBasedNotifier = Private(routeBasedNotifierProvider);
1615
$rootScope = $injector.get('$rootScope');
1716
}));
1817

18+
afterEach(() => {
19+
Notifier.prototype._notifs.length = 0;
20+
});
21+
1922
describe('#warning()', () => {
2023
it('adds a warning notification', () => {
2124
routeBasedNotifier.warning('wat');

src/ui/public/test_harness/test_harness.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import chrome from 'ui/chrome';
66
import Nonsense from 'Nonsense';
77
import sinon from 'sinon';
88
import _ from 'lodash';
9+
import Notifier from 'ui/notify/notifier';
910

1011
import StackTraceMapper from 'ui/stack_trace_mapper';
1112
import { parse } from 'url';
@@ -55,6 +56,13 @@ before(function () {
5556
sinon.useFakeXMLHttpRequest();
5657
});
5758

59+
beforeEach(function () {
60+
if (Notifier.prototype._notifs.length) {
61+
Notifier.prototype._notifs.length = 0;
62+
throw new Error('notifications were left in the notifier');
63+
}
64+
});
65+
5866

5967
/*** Kick off mocha, called at the end of test entry files ***/
6068
exports.bootstrap = function () {

0 commit comments

Comments
 (0)