Add stricter object checking

This commit is contained in:
Kevin Sawicki
2015-07-07 12:20:01 -07:00
parent 7fbcd147d5
commit 93069fad75
2 changed files with 5 additions and 1 deletions

View File

@@ -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", ->

View File

@@ -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'