bdd

package
v0.0.2-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bdd wires the hex/webtest client into a hex/bdd suite as a set of standard Gherkin step definitions, giving apps a react-testing-library-flavoured browser-test vocabulary in .feature files:

Feature: dashboard

  Scenario: authenticated user sees welcome
    When I visit "/dashboard"
    Then the response status should be 200
    And I should see "Welcome, Alice"
    And "h1" should have text "Welcome, Alice"
    And there should be 3 elements matching ".user-card"
    And "button[data-testid=add-user]" should exist

  Scenario: bad credentials
    When I post form to "/login":
      | email    | user@example.com |
      | password | wrong            |
    Then the response status should be 401
    And I should see "bad credentials"

Usage from a test:

func TestFeatures(t *testing.T) {
    app := hextest.NewApp(t, myproviders...)
    suite := bdd.NewSuite(t)
    webtestbdd.Register(suite, func() *webtest.Client {
        return webtest.New(t, app)
    })
    suite.Run()
}

The Client factory is called ONCE PER SCENARIO so each scenario gets a fresh cookie jar and a clean request state. State that should persist across scenarios (seeded rows, cached files, etc.) belongs on the app itself, not the client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(suite *bdd.Suite, factory func() *webtest.Client)

Register attaches the standard webtest step vocabulary to suite. factory is invoked once per scenario to build a fresh Client bound to the app under test.

Register does not run the suite — callers call suite.Run() when they've added any additional app-specific steps.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL