{"action":"created","issue":{"url":"https://api.github.com/repos/Codeception/CodeceptJS/issues/898","repository_url":"https://api.github.com/repos/Codeception/CodeceptJS","labels_url":"https://api.github.com/repos/Codeception/CodeceptJS/issues/898/labels{/name}","comments_url":"https://api.github.com/repos/Codeception/CodeceptJS/issues/898/comments","events_url":"https://api.github.com/repos/Codeception/CodeceptJS/issues/898/events","html_url":"https://github.com/Codeception/CodeceptJS/issues/898","id":292667843,"number":898,"title":"Failed assertion with chai-as-promised is not working","user":{"login":"mingfang","id":821695,"avatar_url":"https://avatars1.githubusercontent.com/u/821695?v=4","gravatar_id":"","url":"https://api.github.com/users/mingfang","html_url":"https://github.com/mingfang","followers_url":"https://api.github.com/users/mingfang/followers","following_url":"https://api.github.com/users/mingfang/following{/other_user}","gists_url":"https://api.github.com/users/mingfang/gists{/gist_id}","starred_url":"https://api.github.com/users/mingfang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mingfang/subscriptions","organizations_url":"https://api.github.com/users/mingfang/orgs","repos_url":"https://api.github.com/users/mingfang/repos","events_url":"https://api.github.com/users/mingfang/events{/privacy}","received_events_url":"https://api.github.com/users/mingfang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-01-30T06:33:17Z","updated_at":"2018-02-16T14:47:05Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"#### What are you trying to achieve?\r\nI'm trying to use chai-as-promised for assertions.\r\nIt works when the assertion passes but it does not work when the assertion fails.\r\n\r\n#### What do you get instead?\r\nI get this error\r\n```\r\n(node:40795) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected { Object (_readableState, readable, ...) } to have property 'foo'\r\n(node:40795) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.\r\n```\r\nand the test is marked as passed when though it should fail.\r\n\r\n> Provide console output if related. Use `--verbose` mode for more details.\r\n\r\n```bash\r\n./node_modules/codeceptjs/bin/codecept.js run  --verbose\r\nCodeceptJS v1.1.2\r\n\r\n   [1] Starting recording promises\r\n   Emitted | suite.before ([object Object])\r\n   [1] Queued | hook Nightmare._beforeSuite()\r\n   [1] Queued | hook Mochawesome._beforeSuite()\r\n   [1] Queued | hook REST._beforeSuite()\r\n   Emitted | test.before\r\n   [1] Queued | hook Nightmare._before()\r\n   [1] Queued | hook Mochawesome._before()\r\n   [1] Queued | hook REST._before()\r\n   Emitted | test.start ([object Object])\r\n   Emitted | step.before (I send get request \"http://google.com\")\r\n   [1] Queued | hook Nightmare._beforeStep()\r\n   [1] Queued | hook Mochawesome._beforeStep()\r\n   [1] Queued | hook REST._beforeStep()\r\n   [1] Queued | sendGetRequest: \"http://google.com\"\r\n   Emitted | step.after (I send get request \"http://google.com\")\r\n   [1] Queued | hook Nightmare._afterStep()\r\n   [1] Queued | hook Mochawesome._afterStep()\r\n   [1] Queued | hook REST._afterStep()\r\n   [1] Queued | step passed\r\n   [1] Queued | return result\r\n   [1] Queued | fire test.passed\r\n   [1] Queued | finish test\r\n   Emitted | step.start (I send get request \"http://google.com\")\r\n • I send get request \"http://google.com\"\r\n   Emitted | step.passed (I send get request \"http://google.com\")\r\n   Step finished in 0.06 sec\r\n   Emitted | test.passed ([object Object])\r\n ✓ OK in 103ms\r\n\r\n(node:40934) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected { Object (_readableState, readable, ...) } to have property 'foo'\r\n(node:40934) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.\r\n   Emitted | test.after\r\n   [1] Queued | hook Nightmare._after()\r\n   [1] Queued | hook Mochawesome._after()\r\n   [1] Queued | hook REST._after()\r\n   Emitted | suite.after ([object Object])\r\n   [1] Queued | hook Nightmare._afterSuite()\r\n   [1] Queued | hook Mochawesome._afterSuite()\r\n   [1] Queued | hook REST._afterSuite()\r\n\r\n  OK  | 1 passed   // 1s\r\n   Emitted | global.result ([object Object])\r\n   [1] Queued | hook Nightmare._finishTest()\r\n   [1] Queued | hook Mochawesome._finishTest()\r\n   [1] Queued | hook REST._finishTest()\r\n\r\n```\r\n\r\n> Provide test source code if related\r\n\r\n```js\r\nScenario('test chai', async(I) => {\r\n  const res =  I.sendGetRequest(\"http://google.com\")\r\n  const chai = require('chai')\r\n  chai.use(require('chai-as-promised'))\r\n  const expect = chai.expect\r\n  expect(res)\r\n    // .to.eventually.have.property(\"body\") //this works\r\n    .to.eventually.have.property(\"foo\") //this does not work\r\n});\r\n\r\n```\r\n\r\n### Details\r\n\r\n* CodeceptJS version: 1.1.2\r\n* NodeJS Version: 8.9.4\r\n* Operating System: OSX\r\n"},"comment":{"url":"https://api.github.com/repos/Codeception/CodeceptJS/issues/comments/366254884","html_url":"https://github.com/Codeception/CodeceptJS/issues/898#issuecomment-366254884","issue_url":"https://api.github.com/repos/Codeception/CodeceptJS/issues/898","id":366254884,"user":{"login":"dmydry","id":15157181,"avatar_url":"https://avatars0.githubusercontent.com/u/15157181?v=4","gravatar_id":"","url":"https://api.github.com/users/dmydry","html_url":"https://github.com/dmydry","followers_url":"https://api.github.com/users/dmydry/followers","following_url":"https://api.github.com/users/dmydry/following{/other_user}","gists_url":"https://api.github.com/users/dmydry/gists{/gist_id}","starred_url":"https://api.github.com/users/dmydry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmydry/subscriptions","organizations_url":"https://api.github.com/users/dmydry/orgs","repos_url":"https://api.github.com/users/dmydry/repos","events_url":"https://api.github.com/users/dmydry/events{/privacy}","received_events_url":"https://api.github.com/users/dmydry/received_events","type":"User","site_admin":false},"created_at":"2018-02-16T14:47:05Z","updated_at":"2018-02-16T14:47:05Z","author_association":"NONE","body":"Hello guys! I have been stuck with this problem and just realized what's going on.\r\nFirst of all, please check the next code:\r\n```\r\nScenario('Async', async I => {\r\n    await assert.equal(false, true);\r\n});\r\n\r\nScenario('Sync', I => {\r\n  assert.equal(false, true);\r\n});\r\n```\r\n\r\n**The first one will be passed, but we will se a console message:**\r\n```\r\nAsync\r\n ✓ OK in 3ms\r\n\r\n(node:77727) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: false == true\r\n```\r\n\r\n**The second one will be failed:**\r\n```\r\nSync\r\n ✖ FAILED in 635ms\r\n\r\n-- FAILURES:\r\n\r\n  1) Test\r\n       Sync:\r\n\r\n      false == true\r\n      + expected - actual\r\n\r\n      -false\r\n      +true\r\n```\r\n\r\nThe console message above is trying to help us and push us to handle a promise rejection. The most simple and common way to do this is to to use `try...catch`. \r\nMy problem was to find a way to reject a test inside a catch. So ended up with the next code:\r\n\r\n```\r\nimport { recorder } from 'codeceptjs';\r\n\r\nScenario('Async', async I => {\r\n  try {\r\n    assert.equal(false, true);\r\n  } catch (e) {\r\n    recorder.throw(e);\r\n  }\r\n});\r\n\r\nScenario('Sync', I => {\r\n  assert.equal(false, true);\r\n});\r\n```\r\n\r\nIn case if anyone else will be looking for answers.\r\n> **CodeceptJS Async Await handle promise rejection**\r\n> **CodeceptJS Async assert**\r\n> **CodeceptJS Manually stop test**"}}
{"actor":{"display_login":"dmydry"}}