{"action":"created","issue":{"url":"https://api.github.com/repos/chaijs/chai/issues/842","repository_url":"https://api.github.com/repos/chaijs/chai","labels_url":"https://api.github.com/repos/chaijs/chai/issues/842/labels{/name}","comments_url":"https://api.github.com/repos/chaijs/chai/issues/842/comments","events_url":"https://api.github.com/repos/chaijs/chai/issues/842/events","html_url":"https://github.com/chaijs/chai/issues/842","id":183237666,"number":842,"title":"Failed 'expect' statement timing out w/Mocha & Chai","user":{"login":"adamstelle","id":546314,"avatar_url":"https://avatars.githubusercontent.com/u/546314?v=3","gravatar_id":"","url":"https://api.github.com/users/adamstelle","html_url":"https://github.com/adamstelle","followers_url":"https://api.github.com/users/adamstelle/followers","following_url":"https://api.github.com/users/adamstelle/following{/other_user}","gists_url":"https://api.github.com/users/adamstelle/gists{/gist_id}","starred_url":"https://api.github.com/users/adamstelle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamstelle/subscriptions","organizations_url":"https://api.github.com/users/adamstelle/orgs","repos_url":"https://api.github.com/users/adamstelle/repos","events_url":"https://api.github.com/users/adamstelle/events{/privacy}","received_events_url":"https://api.github.com/users/adamstelle/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-15T22:52:34Z","updated_at":"2016-10-15T23:31:33Z","closed_at":"2016-10-15T23:30:25Z","body":"I'm getting unexpected timeout behavior using Mocha and Chai's 'expect' statement when a test fails.\r\n\r\nThe code:\r\n```javascript\r\nrequire('./lib/test-env.js');\r\n\r\nconst expect = require('chai').expect;\r\nconst estimateQuery = require('../lib/estimate-query-helper.js');\r\n\r\ndescribe('testing auth routes', function() {\r\n  describe('testing estimate query helper', function() {\r\n    it('should return an average daily rate and occupancy rate', (done) => {\r\n      estimateQuery.getEstimate()\r\n      .then(result => {\r\n        expect(result[0]['avg(`Average Daily Rate`)']).to.be.a('number');\r\n        expect(result[0]['avg(`Occupancy Rate LTM`)']).to.be.a('number');\r\n        done();\r\n      });\r\n    });\r\n  });\r\n});\r\n```\r\n\r\nWhen I run this with correct expect values, test passes w/no timeout (and I've checked to see the returned values are all correct). But when I change 'number' to (for example) 'string' on either of the statements, rather than failing and throwing 'Expected ..., Actual ...\" error, it times out.\r\n\r\nThanks in advance for your help!\r\n\r\nFor reference, here's the function it's calling:\r\n```javascript\r\nexports.getEstimate = function() {\r\n  debug('running estimate query against SQLdb');\r\n  return new Promise((resolve, reject) => {\r\n    let tries = 0;\r\n    mysql.createConnection({\r\n      host: '104.198.143.37',\r\n      user: 'root',\r\n      password: 'D0wnr1ght',\r\n      database : 'firstdb',\r\n    }).then(function _getEstimate(connection){\r\n      var latLow = initLat - ((tries + 1) * 0.0042);\r\n      var latHigh = initLat + ((tries + 1) * 0.0042);\r\n      var lngLow = initLng - ((tries + 1) * 0.0060);\r\n      var lngHigh = initLng + ((tries + 1) * 0.0060);\r\n      connection.query('select count(*),avg(`Average Daily Rate`), avg(`Occupancy Rate LTM`) from `airbnb_summary` where (`airbnb_summary`.`Listing Type` = \"Private room\"  and `Average Daily Rate` >0 and  `Number of Bookings LTM`>4 and`airbnb_summary`.`Longitude` between '+ lngLow +' and '+ lngHigh+' AND `airbnb_summary`.`Latitude` between '+ latLow +' and '+ latHigh +' );')\r\n      .then(rows => {\r\n        if (tries > 10) return reject(createError(500, 'something went wrong'));\r\n        if (rows[0]['count(*)'] < 10) return _getEstimate();\r\n        rows.tries = tries;\r\n        resolve(rows);\r\n      })\r\n      .catch(err => {\r\n        console.error(err);\r\n        reject(err);\r\n      });\r\n    });\r\n  });\r\n};"},"comment":{"url":"https://api.github.com/repos/chaijs/chai/issues/comments/254017518","html_url":"https://github.com/chaijs/chai/issues/842#issuecomment-254017518","issue_url":"https://api.github.com/repos/chaijs/chai/issues/842","id":254017518,"user":{"login":"meeber","id":17260989,"avatar_url":"https://avatars.githubusercontent.com/u/17260989?v=3","gravatar_id":"","url":"https://api.github.com/users/meeber","html_url":"https://github.com/meeber","followers_url":"https://api.github.com/users/meeber/followers","following_url":"https://api.github.com/users/meeber/following{/other_user}","gists_url":"https://api.github.com/users/meeber/gists{/gist_id}","starred_url":"https://api.github.com/users/meeber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meeber/subscriptions","organizations_url":"https://api.github.com/users/meeber/orgs","repos_url":"https://api.github.com/users/meeber/repos","events_url":"https://api.github.com/users/meeber/events{/privacy}","received_events_url":"https://api.github.com/users/meeber/received_events","type":"User","site_admin":false},"created_at":"2016-10-15T23:31:33Z","updated_at":"2016-10-15T23:31:33Z","body":"@adamstelle The solution posted by @vieiralucas's is correct, but I want to clarify one thing:\r\n\r\nEven when using the `done` syntax, a failed Chai assertion would normally cause the test to immediately fail instead of timeout, despite execution stopping before calling `done()`. The reason it doesn't in your example is because the failed assertion error is being swallowed inside the promise. If you're using Node v6.6+, you should be receiving an \"UnhandledPromiseRejectionWarning\".\r\n\r\nThis doesn't really have anything to do with Chai and Mocha but rather the behavior of promises. For example...\r\n\r\n```js\r\nPromise\r\n.resolve()\r\n.then(() => {\r\n  console.log(\"hi\");\r\n  throw Error(\"STOP\");\r\n  console.log(\"bye\");\r\n});\r\n```\r\n\r\n...would output \"hi\" only without throwing an error or outputting \"bye\"."}}
{"actor":{"display_login":"meeber"}}