Skip to content

Commit e4ee88e

Browse files
timbellFoxandxss
authored andcommitted
active api to return current number of toasts
Closes #142
1 parent 050fac8 commit e4ee88e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/toastr.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
var containerDefer = $q.defer();
1818

1919
var toast = {
20+
active: active,
2021
clear: clear,
2122
error: error,
2223
info: info,
@@ -28,6 +29,10 @@
2829
return toast;
2930

3031
/* Public API */
32+
function active() {
33+
return toasts.length;
34+
}
35+
3136
function clear(toast) {
3237
// Bit of a hack, I will remove this soon with a BC
3338
if (arguments.length === 1 && !toast) { return; }

test/toastr_spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,17 @@ describe('toastr', function() {
372372
animationFlush();
373373
expect($document).not.toHaveToastContainer();
374374
});
375+
376+
it('has a list of active toasts', function() {
377+
openToasts(5);
378+
expect(toastr.active()).toBe(5);
379+
clickToast();
380+
clickToast();
381+
expect(toastr.active()).toBe(3);
382+
intervalFlush();
383+
animationFlush();
384+
expect(toastr.active()).toBe(0);
385+
});
375386
});
376387

377388
describe('container', function() {

0 commit comments

Comments
 (0)