Skip to content

Commit

Permalink
Merge pull request elastic#8822 from spalger/fix/tests/ensure-empty-n…
Browse files Browse the repository at this point in the history
…otifs

[tests] ensure that the notifier is emptied by each test
  • Loading branch information
spalger authored Oct 25, 2016
2 parents 6b5011a + 34659fb commit 973222c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/ui/public/notify/__tests__/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ describe('Notifier', function () {

beforeEach(function () {
params = { location: 'foo' };
while (Notifier.prototype._notifs.pop()); // clear global notifications
notifier = new Notifier(params);
});

afterEach(function () {
Notifier.prototype._notifs.length = 0;
});

describe('#constructor()', function () {
it('sets #from from given location', function () {
expect(notifier.from).to.equal(params.location);
Expand Down Expand Up @@ -465,13 +468,12 @@ describe('Directive Notification', function () {
scope;
});

while (Notifier.prototype._notifs.pop()); // clear global notifications

notifier = new Notifier({ location: 'directiveFoo' });
directiveNotification = notifier.directive(directiveParam, customParams);
});

afterEach(() => {
Notifier.prototype._notifs.length = 0;
directiveNotification.clear();
scope.$destroy();
});
Expand Down
5 changes: 4 additions & 1 deletion src/ui/public/route_based_notifier/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ describe('ui/route_based_notifier', function () {

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(($injector) => {
remove(Notifier.prototype._notifs); // hack to reset the global notification array
const Private = $injector.get('Private');
routeBasedNotifier = Private(routeBasedNotifierProvider);
$rootScope = $injector.get('$rootScope');
}));

afterEach(() => {
Notifier.prototype._notifs.length = 0;
});

describe('#warning()', () => {
it('adds a warning notification', () => {
routeBasedNotifier.warning('wat');
Expand Down
8 changes: 8 additions & 0 deletions src/ui/public/test_harness/test_harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import chrome from 'ui/chrome';
import Nonsense from 'Nonsense';
import sinon from 'sinon';
import _ from 'lodash';
import Notifier from 'ui/notify/notifier';

import StackTraceMapper from 'ui/stack_trace_mapper';
import { parse } from 'url';
Expand Down Expand Up @@ -55,6 +56,13 @@ before(function () {
sinon.useFakeXMLHttpRequest();
});

beforeEach(function () {
if (Notifier.prototype._notifs.length) {
Notifier.prototype._notifs.length = 0;
throw new Error('notifications were left in the notifier');
}
});


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

0 comments on commit 973222c

Please sign in to comment.