Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

ANN vitest-bdd: ReScript testing with vitest (and source maps !)

$
0
0

Awesome !

Let me know how it goes.

Maybe also explore the Gherkins way. I found them super useful for “behavior” testing (like a complicated, multi-stage input). I use a mix of unit and feature tests and am super happy because they all end up in the same test infrastructure.

Example:

# test/TextEntry.feature

Feature: TextEntry

  Scenario: enter a single int
    Given template "I am [int] years old"
    When I type 4
    And I type 9
    And I am done
    Then I should receive "I am 49 years old"

  Scenario: enter fractions
    Given template "x = \frac{[int]}{[int]}"
    When I type 4
    And I type 9
    And I am done
    And I type 7
    And I type 4
    And I am done
    Then I should receive "x = \frac{49}{74}"

  Scenario: editing state
    Given template "x = \frac{[int]}{[int]}"
    When I type 4
    Then display should be "x = \frac{{\color{pink}4}}{{\color{violet}?}}"
open VitestBdd
given("template {string}", ({step}, str: string) => {
  let entry = TextEntry.make(str)
  step("I type {number}", (nb: int) => {
    entry.append(nb->Int.toString)
  })
  step("I am done", () => {
    entry.next()
  })
  step("I should receive {string}", (str: string) => {
    expect(entry.text).toEqual(str)
  })
  step("display should be {string}", (str: string) => {
    expect(entry.display).toEqual(str)
  })
})

Cool VS Code extensions for vitest and gherkins:

  • Vitest extension (for proper test integration)
  • Cucumber extension (for nice colors)

Viewing all articles
Browse latest Browse all 2592

Trending Articles