mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Add stricter object checking
This commit is contained in:
@@ -8,16 +8,19 @@ describe "Notification", ->
|
||||
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()
|
||||
|
||||
it "throws an error when created with a non-string detail", ->
|
||||
expect(-> new Notification('error', 'message', detail: 3)).toThrow()
|
||||
expect(-> new Notification('error', 'message', detail: false)).toThrow()
|
||||
expect(-> new Notification('error', 'message', detail: {})).toThrow()
|
||||
expect(-> new Notification('error', 'message', detail: [])).toThrow()
|
||||
|
||||
describe "::getTimestamp()", ->
|
||||
it "returns a Date object", ->
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{Emitter} = require 'event-kit'
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
# Public: A notification to the user containing a message and type.
|
||||
module.exports =
|
||||
@@ -15,7 +16,7 @@ class Notification
|
||||
if typeof @message isnt 'string'
|
||||
throw new Error("Notification must be created with string message: #{@message}")
|
||||
|
||||
if typeof @options isnt 'object'
|
||||
unless _.isObject(@options) and not _.isArray(@options)
|
||||
throw new Error("Notification must be created with an options object: #{@options}")
|
||||
|
||||
if @options?.detail? and typeof @options.details isnt 'string'
|
||||
|
||||
Reference in New Issue
Block a user