Skip to content

Commit

Permalink
test: test the alerts module
Browse files Browse the repository at this point in the history
Check that alerts can be registered and displayed via the
alerts module
  • Loading branch information
joshje committed May 26, 2017
1 parent 9a76dd7 commit 71bd6c4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/alerts.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var test = require('tap-only');
var testUtils = require('./utils');
var alerts = require('../lib/alerts');

var exampleAlert = function (id, type) {
type = type || 'info';
return {
msg: 'Example alert ' + id,
type: type,
};
}

test('register an alert', function (t) {
t.plan(1);

alerts.registerAlerts([ exampleAlert(1) ]);
t.equal(alerts.displayAlerts().trim(), exampleAlert(1).msg,
'alert is displayed');
});

test('register the same alert multiple times', function (t) {
t.plan(1);

alerts.registerAlerts([ exampleAlert(1) ]);
alerts.registerAlerts([ exampleAlert(1) ]);
t.equal(alerts.displayAlerts().trim(), exampleAlert(1).msg,
'alert is only displayed once');
});

test('register two different alerts', function (t) {
t.plan(2);

alerts.registerAlerts([ exampleAlert(1) ]);
alerts.registerAlerts([ exampleAlert(2) ]);
const displayedAlerts = alerts.displayAlerts();
t.contains(displayedAlerts, exampleAlert(1).msg,
'first alert is displayed');
t.contains(displayedAlerts, exampleAlert(2).msg,
'second alert is displayed');
});

0 comments on commit 71bd6c4

Please sign in to comment.