[notifier] ensure that notifications are not left around

This commit is contained in:
spalger 2016-10-18 15:48:01 -07:00
parent 0757c45dfa
commit 2dbb462bc1
4 changed files with 19 additions and 6 deletions

View file

@ -51,9 +51,9 @@ describe('ResponseWriter class', function () {
it('collects the aggConfigs from each column in aggStack', function () {
let aggs = [
{ type: 'date_histogram', schema: 'segment', params: { field: '@timestamp' } },
{ type: 'date_histogram', schema: 'segment', params: { field: 'time' } },
{ type: 'terms', schema: 'segment', params: { field: 'extension' } },
{ type: 'avg', schema: 'metric', params: { field: '@timestamp' } }
{ type: 'avg', schema: 'metric', params: { field: 'bytes' } }
];
getColumns.returns(aggs.map(function (agg) {

View file

@ -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; // clear global notifications
});
describe('#constructor()', function () {
it('sets #from from given location', function () {
expect(notifier.from).to.equal(params.location);
@ -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; // clear global notifications
directiveNotification.clear();
scope.$destroy();
});

View file

@ -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; // reset the global notification array
});
describe('#warning()', () => {
it('adds a warning notification', () => {
routeBasedNotifier.warning('wat');

View file

@ -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';
@ -55,6 +56,13 @@ before(function () {
sinon.useFakeXMLHttpRequest();
});
beforeEach(function () {
if (Notifier.prototype._notifs.length) {
Notifier.prototype._notifs.length = 0;
throw new TypeError('notifications were left in the notifier');
}
});
/*** Kick off mocha, called at the end of test entry files ***/
exports.bootstrap = function () {