Skip to content

feat: add codeceptjs/assertions subpath and hopeThat.noErrors()#5526

Merged
DavertMik merged 1 commit into4.xfrom
feat/hopethat-noerrors-assertions
Apr 20, 2026
Merged

feat: add codeceptjs/assertions subpath and hopeThat.noErrors()#5526
DavertMik merged 1 commit into4.xfrom
feat/hopethat-noerrors-assertions

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

Summary

  • New codeceptjs/assertions subpath exports the built-in assertion factories (equals, includes, empty, truth) so they can be used directly from scenarios and custom helpers — no chai/jest/node:assert needed to get CodeceptJS-style failure messages.
  • New hopeThat.noErrors() on codeceptjs/effects. Call it once at the end of a scenario to fail the test if any hopeThat(...) soft assertion failed. Failures are collected into a module-level array that resets on event.test.before, and noErrors() throws a single empty('soft assertions') assertion with an array diff instead of a raw Error. Existing conditionalError notes on test.notes are preserved for reporters.
  • New docs/assertions.md page covering built-in see/dontSee, ExpectHelper, the new codeceptjs/assertions API, external libraries, reusable custom helpers, WebElement-based assertions, soft assertions (hopeThat + hopeThat.noErrors), and secret() masking.

Example

import { hopeThat } from 'codeceptjs/effects'

Scenario('registration form shows every validation error at once', async ({ I }) => {
  I.amOnPage('/register')
  I.click('Create Account')

  await hopeThat(() => I.see('Email is required', '#email-error'))
  await hopeThat(() => I.see('Password is required', '#password-error'))
  await hopeThat(() => I.see('You must accept the terms', '#terms-error'))

  hopeThat.noErrors()
})
import { equals, includes, empty } from 'codeceptjs/assertions'

const total = await I.grabTextFrom('.cart-total')
equals('cart total').assert(total, '$42.00')
// expected cart total "$10.00" to equal "$42.00"

Test plan

  • Verified codeceptjs/assertions subpath resolves and each factory produces the expected failure message
  • Verified hopeThat.noErrors() end-to-end against test/acceptance/codecept.Playwright.js:
    • scenario with no failures → passes
    • scenario with two failed hopeThat calls → fails with aggregated expected soft assertions '[...]' to be empty and an array diff
    • subsequent scenario starts clean (state reset on test.before)
  • Existing lib/effects.js unit tests still pass (no behavior change to the happy path; only adds a push-and-forget to the failures array in the catch handler)

🤖 Generated with Claude Code

- Expose the built-in assertion factories (equals, includes, empty,
  truth) at a new `codeceptjs/assertions` subpath so users can write
  the same CodeceptJS-style assertions from scenarios and custom
  helpers, without depending on chai/jest/node:assert.

- Add `hopeThat.noErrors()` that aggregates soft-assertion failures
  collected during the current test and fails the scenario with a
  single `empty('soft assertions')` assertion if any were recorded.
  Failures reset on `event.test.before` so they do not leak across
  tests. The existing `conditionalError` notes on `test.notes` are
  preserved for reporters.

- New docs/assertions.md covering built-in see/dontSee, ExpectHelper,
  codeceptjs/assertions, external libraries, reusable custom helpers,
  WebElement-based assertions, soft assertions (hopeThat +
  hopeThat.noErrors), and secret masking.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DavertMik DavertMik merged commit e782270 into 4.x Apr 20, 2026
10 checks passed
@DavertMik DavertMik deleted the feat/hopethat-noerrors-assertions branch April 20, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant