{"action":"created","issue":{"url":"https://api.github.com/repos/chaijs/chai/issues/472","labels_url":"https://api.github.com/repos/chaijs/chai/issues/472/labels{/name}","comments_url":"https://api.github.com/repos/chaijs/chai/issues/472/comments","events_url":"https://api.github.com/repos/chaijs/chai/issues/472/events","html_url":"https://github.com/chaijs/chai/issues/472","id":91617348,"number":472,"title":"should undefined be classed as empty in expect empty  ","user":{"login":"Daveloper87","id":8749809,"avatar_url":"https://avatars.githubusercontent.com/u/8749809?v=3","gravatar_id":"","url":"https://api.github.com/users/Daveloper87","html_url":"https://github.com/Daveloper87","followers_url":"https://api.github.com/users/Daveloper87/followers","following_url":"https://api.github.com/users/Daveloper87/following{/other_user}","gists_url":"https://api.github.com/users/Daveloper87/gists{/gist_id}","starred_url":"https://api.github.com/users/Daveloper87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Daveloper87/subscriptions","organizations_url":"https://api.github.com/users/Daveloper87/orgs","repos_url":"https://api.github.com/users/Daveloper87/repos","events_url":"https://api.github.com/users/Daveloper87/events{/privacy}","received_events_url":"https://api.github.com/users/Daveloper87/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chaijs/chai/labels/easy-fix","name":"easy-fix","color":"bfe5bf"},{"url":"https://api.github.com/repos/chaijs/chai/labels/pull-request-wanted","name":"pull-request-wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-28T17:11:31Z","updated_at":"2015-06-29T00:15:09Z","closed_at":null,"body":"I have found a potential issue with the .empty assertion in expect. Running in a node.js context on Mac OSX\r\nIf you run :\r\n```\r\nexpect().to.be.empty\r\nexpect(undefined).to.be.empty;\r\n```\r\nThis will happily work as a passing test assertion. Is this an intended behavior?\r\nMy only problem would be if you are creating a collection dynamically and it comes through as undefined, you may assume your code is working when it is just returning undefined.\r\n\r\nObviously you could add something like:\r\n```\r\nexpect(someData).to.be.an('object');\r\n```\r\nBut I feel it should fail if it receives undefined to avoid assertions passing when no collection, object or string was passed.\r\n\r\nAlso as a side note, the string check here does not execute:\r\nhttps://github.com/chaijs/chai/blob/master/lib/chai/core/assertions.js#L379\r\n\r\nIt still works because the code runs\r\n```\r\n!expected\r\n```\r\n which would return true for an empty string. It looks like it supposed to be obj instead of object\r\n```\r\n if (Array.isArray(obj) || 'string' === typeof obj)\r\n```\r\n The 'string' check could be removed based on !expected, but it is probably nicer to be explicit anyway."},"comment":{"url":"https://api.github.com/repos/chaijs/chai/issues/comments/116362150","html_url":"https://github.com/chaijs/chai/issues/472#issuecomment-116362150","issue_url":"https://api.github.com/repos/chaijs/chai/issues/472","id":116362150,"user":{"login":"Daveloper87","id":8749809,"avatar_url":"https://avatars.githubusercontent.com/u/8749809?v=3","gravatar_id":"","url":"https://api.github.com/users/Daveloper87","html_url":"https://github.com/Daveloper87","followers_url":"https://api.github.com/users/Daveloper87/followers","following_url":"https://api.github.com/users/Daveloper87/following{/other_user}","gists_url":"https://api.github.com/users/Daveloper87/gists{/gist_id}","starred_url":"https://api.github.com/users/Daveloper87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Daveloper87/subscriptions","organizations_url":"https://api.github.com/users/Daveloper87/orgs","repos_url":"https://api.github.com/users/Daveloper87/repos","events_url":"https://api.github.com/users/Daveloper87/events{/privacy}","received_events_url":"https://api.github.com/users/Daveloper87/received_events","type":"User","site_admin":false},"created_at":"2015-06-29T00:15:09Z","updated_at":"2015-06-29T00:15:09Z","body":"Hi @keithamus , Thanks for responding. I have opened a pull request for that fix here: \r\nhttps://github.com/chaijs/chai/pull/473\r\n\r\nIn regards to the .empty on undefined checks. I only actually noticed it because I was writing my tests first, and was slightly surprised that my empty function passed, but I very much agree with your point about checking the return type and it not being worth a breaking change, I just did not expect undefined to pass the empty check. \r\n\r\nOne little thing I wanted to note as well just in case someone else comes across this issue.\r\n```\r\nexpect(null).to.be.empty;\r\n```\r\nonly fails because the line: https://github.com/chaijs/chai/blob/master/lib/chai/core/assertions.js#L381\r\n```\r\nelse if (typeof obj === 'object') {\r\n```\r\nbecause typeof null is === 'object',   it just fails with a TypeError trying to Object.keys on null, otherwise that would pass too.\r\n\r\nObviously not a problem because it fails, but I am just adding it to this issue in case someone else highlights it. \r\n\r\nThanks again"}}