{"id":16294908,"url":"https://github.com/jan-molak/chai-smoothie","last_synced_at":"2025-03-20T04:30:43.455Z","repository":{"id":11176025,"uuid":"68633473","full_name":"jan-molak/chai-smoothie","owner":"jan-molak","description":"Chai assertions for Serenity/JS and Protractor","archived":false,"fork":false,"pushed_at":"2022-12-07T03:07:06.000Z","size":902,"stargazers_count":13,"open_issues_count":10,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T23:02:22.251Z","etag":null,"topics":["angular","chai-assertions","protractor","serenity","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jan-molak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-19T18:21:31.000Z","updated_at":"2020-04-17T00:37:14.000Z","dependencies_parsed_at":"2023-01-13T16:22:12.086Z","dependency_job_id":null,"html_url":"https://github.com/jan-molak/chai-smoothie","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-molak%2Fchai-smoothie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-molak%2Fchai-smoothie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-molak%2Fchai-smoothie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-molak%2Fchai-smoothie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jan-molak","download_url":"https://codeload.github.com/jan-molak/chai-smoothie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047647,"owners_count":20389206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","chai-assertions","protractor","serenity","typescript"],"created_at":"2024-10-10T20:16:52.554Z","updated_at":"2025-03-20T04:30:42.874Z","avatar_url":"https://github.com/jan-molak.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chai Smoothie - Protractor assertions for Chai\n\n[![npm version](https://badge.fury.io/js/chai-smoothie.svg)](https://badge.fury.io/js/chai-smoothie)\n[![Build Status](https://travis-ci.org/jan-molak/chai-smoothie.svg?branch=master)](https://travis-ci.org/jan-molak/chai-smoothie)\n[![Coverage Status](https://coveralls.io/repos/github/jan-molak/chai-smoothie/badge.svg)](https://coveralls.io/github/jan-molak/chai-smoothie)\n[![Dependencies](https://david-dm.org/jan-molak/chai-smoothie.svg)](https://david-dm.org/jan-molak/chai-smoothie)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n\n[Chai Smoothie](https://github.com/jan-molak/chai-smoothie) smooths out the sharp angles of your\n[Protractor](https://github.com/angular/protractor)-powered automated web tests.\n\n\nThe library provides a set of custom\n[Chai](http://chaijs.com/)\nassertions to help your Protractor-based [Serenity/JS](https://github.com/jan-molak/serenity-js) tests\nexpress their intent better, give assertion errors more meaning,\nand reduce the amount of time your team spends troubleshooting the failures.\n\nChai Smoothie comes with [TypeScript](https://www.typescriptlang.org/) typings\nand works with [Chai-as-Promised](https://github.com/domenic/chai-as-promised),\n[Serenity/JS](https://github.com/jan-molak/serenity-js),\nand plain [Protractor](https://github.com/angular/protractor) tests too!\n\n---\n\nTo add Chai Smoothie to your [Node.js](https://nodejs.org/) project:\n\n```\nnpm install chai-smoothie --save-dev\n```\n\n---\n\n## The Motivation and The (Missing) Context\n\nLet's assume that we'd like to find out a bit more about the state of an HTML element defined as:\n\n``` html\n\u003ch1 id=\"title\"\u003eChai Smoothie is delicious!\u003c/h1\u003e\n```\n\nA [typical approach](http://goo.gl/Zrk4Vj) used in Protractor tests\nto check if an element is displayed looks more or less like this:\n\n```typescript\nexpect(element(by.id('title')).isDisplayed()).to.eventually.be.true\n```\n\nWhen the element identified by the id of \"`title`\" is displayed, the assertion works fine and won't bother us.\n\nHowever, should the element decide to _not_ appear, the assertion will fail telling us that:\n\n```\nAssertionError: expected false to be true\n```\n\nAlthough Chai is doing its best to tell us the reason of the failure,\nthe only information it has available with this approach is the boolean state of element's visibility.\nThis lack of context is what causes the error message to not be particularly useful.\n\nChai Smoothie gives Chai the missing context and makes the assertion more readable too!\n\n### Vanilla Protractor\n\nIf your automated web tests use Protractor, you can use Chai Smoothie to turn the assertion from the previous example\ninto something a bit more readable:\n\n```typescript\nexpect(element(by.id('title'))).to.eventually.be.displayed\n```\n\nShould the above assertion fail, the error message will be much more informative:\n\n```\nAssertionError: Expected the element located By(css selector, *[id=\"title\"]) to be displayed, but it's not.\n```\n\n### Serenity/JS\n\nSince [Serenity/JS](https://github.com/jan-molak/serenity-js) builds on the shoulders of Protractor,\nyou can use similar syntax with\n[Serenity/JS Questions](https://github.com/jan-molak/serenity-js/blob/master/docs/screenplay-pattern.md#question):\n\n```typescript\nexpect(actor.toSee(WebElement.of(Article.Title))).displayed\n```\n\nUsing the Open-Source Serenity/JS library has a whole lot of other benefits too - [learn more](https://github.com/jan-molak/serenity-js).\n\n## Setting up\n\nFirst of all, install [Chai](http://chaijs.com/) if you don't already have it in your project:\n\n```\nnpm install chai --save-dev\n```\n\nNext, install Chai Smoothie:\n\n```\nnpm install chai-smoothie --save-dev\n```\n\n### TypeScript\n\n```typescript\nimport chai = require('chai');\nchai.use(require('chai-smoothie'));\nconst expect = chai.expect;\n\nexpect(element(by.css('h1'))).to.be.present;\n```\n\n### JavaScript\n\n```javascript\nvar chai = require('chai');\nchai.use(require('chai-smoothie'));\nvar expect = chai.expect;\n\nexpect(element(by.css('h1'))).to.be.present;\n```\n\n\n## Available Assertions\n\nChai Smoothie provides following assertions, each of which can be:\n* negated using the `not` operator: `expect(el).not.to.be.displayed`, `expect(el).not.to.be.present.eventually`, etc.\n* used in conjunction with [chai-as-promised](https://github.com/domenic/chai-as-promised),\nto highlight that the Chai Smoothie assertions return promises: `return expect(el).to.eventually.be.present`.\n\n| Assertion | Example                      | Meaning                                           | Protractor API |\n| ---       | ---                          | ---                                               | ---            |\n| displayed | `expect(el).to.be.displayed` | An element exists in the DOM and is visible      | [`isDisplayed()`](http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.isDisplayed) |\n| enabled   | `expect(el).to.be.enabled`   | A form control element, such as an `input`, is [not disabled](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-disabled)  | [`isEnabled()`](http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.isEnabled) |\n| present   | `expect(el).to.be.present`   | An element exists in the DOM, but can be hidden  | [`isPresent()`](http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.isPresent) |\n| selected  | `expect(el).to.be.selected`  | A form control, such as an `input` `checkbox` is [checked](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-checked) | [`isSelected()`](http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.isSelected) |\n| text() | `expect(el).to.have.text('some text')` or `expect(el).to.contain.text('some text')`| An element have / contains a given text | [`getText()`](http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getText) |\n\n## Getting Help\n\nTo ask about the usage and troubleshooting of Serenity/JS or any of its components, such as Chai Smoothie,\n[post a **serenity-js** tagged question on StackOverflow](http://stackoverflow.com/questions/tagged/serenity-js).\n\n## Your feedback matters!\n\nDo you find Chai Smoothie useful? [Give it a star](https://github.com/jan-molak/chai-smoothie)! \u0026#9733;\n\nFound a bug? Need a feature? Raise [an issue](https://github.com/jan-molak/chai-smoothie/issues?state=open)\nor submit a pull request.\n\nHave feedback? Let me know on twitter: [@JanMolak](https://twitter.com/JanMolak)\n\n## License\n\nThe Chai Smoothie library is licensed under the [Apache-2.0](LICENSE.md) license.\n\nIf you're interested in a commercial license, training, support or bringing your team up to speed with modern software\ndevelopment practices - [please get in touch](https://janmolak.com/about-the-author-e45e048661c#.kxqp57qn9).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjan-molak%2Fchai-smoothie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjan-molak%2Fchai-smoothie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjan-molak%2Fchai-smoothie/lists"}