mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Merge pull request #7769 from atom/ks-validate-notifications
Validate atom.notifications input
This commit is contained in:
commit
11644b41c8
@ -3,6 +3,19 @@ Notification = require '../src/notification'
|
||||
describe "Notification", ->
|
||||
[notification] = []
|
||||
|
||||
it "throws an error when created with a non-string message", ->
|
||||
expect(-> new Notification('error', null)).toThrow()
|
||||
expect(-> new Notification('error', 3)).toThrow()
|
||||
expect(-> new Notification('error', {})).toThrow()
|
||||
expect(-> new Notification('error', false)).toThrow()
|
||||
expect(-> new Notification('error', [])).toThrow()
|
||||
|
||||
it "throws an error when created with non-object options", ->
|
||||
expect(-> new Notification('error', 'message', 'foo')).toThrow()
|
||||
expect(-> new Notification('error', 'message', 3)).toThrow()
|
||||
expect(-> new Notification('error', 'message', false)).toThrow()
|
||||
expect(-> new Notification('error', 'message', [])).toThrow()
|
||||
|
||||
describe "::getTimestamp()", ->
|
||||
it "returns a Date object", ->
|
||||
notification = new Notification('error', 'message!')
|
||||
|
@ -1,4 +1,5 @@
|
||||
{Emitter} = require 'event-kit'
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
# Public: A notification to the user containing a message and type.
|
||||
module.exports =
|
||||
@ -9,6 +10,14 @@ class Notification
|
||||
@dismissed = true
|
||||
@dismissed = false if @isDismissable()
|
||||
@displayed = false
|
||||
@validate()
|
||||
|
||||
validate: ->
|
||||
if typeof @message isnt 'string'
|
||||
throw new Error("Notification must be created with string message: #{@message}")
|
||||
|
||||
unless _.isObject(@options) and not _.isArray(@options)
|
||||
throw new Error("Notification must be created with an options object: #{@options}")
|
||||
|
||||
onDidDismiss: (callback) ->
|
||||
@emitter.on 'did-dismiss', callback
|
||||
|
Loading…
Reference in New Issue
Block a user