miso-tests
Copyright(C) 2016-2025 David M. Johnson (@dmjio)
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Test

Description

An hspec-like miso testing framework. Meant for testing miso Component. The testing framework operates in the jsaddle JSM monad and has access to the DOM courtesy of JSDOM and Playwright.

main :: IO ()
main = runTests $ do
  describe "Arithmetic tests" $ do
    it "2 + 2 = 4" $ do
      (2 + 2) `shouldBe` 4
Synopsis

Test Combinators

describe Source #

Arguments

:: MisoString

Description of test group

-> Test ()

Group of tests to run

-> Test () 

Used to group a bunch of expectations using it. Testing out will include the test description in its output.

it Source #

Arguments

:: MisoString

Name of test to execute

-> Test ()

Test holding multiple expectations

-> Test () 

Used to make multiple expectations using shouldBe / shouldNotBe.

expect :: (Eq a, Show a) => (a -> a -> Bool) -> a -> a -> Test () Source #

Primitive for performing expectations in an it block.

beforeEach :: JSM () -> Test () -> Test () Source #

Execute a JSM action before each it block.

This is useful for scenarios like clearing the global Component state.

afterEach :: JSM () -> Test () -> Test () Source #

Execute a JSM after each it block.

This is useful for scenarios like clearing the global Component state.

shouldBe :: (Show a, Eq a) => a -> a -> Test () Source #

Performs an expectation in an it block.

shouldNotBe :: (Show a, Eq a) => a -> a -> Test () Source #

Perform an expectation in an it block.

The complement of shouldBe.

runTests :: Test a -> IO () Source #

Executes a block of tests in describe blocks.

Utils

jsm :: JSM a -> Test a Source #

Convenience for calling liftJSM

choose Source #

Arguments

:: Int

min

-> Int

max

-> JSM Int 

Return a random integer between the first two provided [min, max)

The maximum is exclusive and the minimum is inclusive

Types

type Test a = StateT TestState JSM a Source #

The monad that executes tests

data TestState Source #

Internal type for managing test state