@@ -0,0 +1,74 @@
13+ , textContentShouldEqual
19+import Data.Foldable (class Foldable, elem, notElem)
20+import Data.Identity (Identity)
21+import Effect.Aff (Aff)
22+import Effect.Class (class MonadEffect, liftEffect)
23+import Effect.Exception as Exception
24+import Web.DOM.Node (textContent)
25+import Web.HTML.HTMLElement (HTMLElement)
26+import Web.HTML.HTMLElement as HTMLElement
27+import Test.Spec (Spec, SpecT, after_, before_, beforeAll_, afterAll_, pending, focus, parallel, sequential) as Spec
28+import Test.Spec as FullSpec
32+type SpecOm ctx a = Spec.SpecT Aff ctx Identity a
34+testOm :: forall ctx a. Monoid a => ctx -> Om ctx () a -> Aff a
35+testOm ctx = Om.runOm ctx { exception: mempty }
37+describe :: forall ctx. String -> Aff ctx -> SpecOm ctx Unit -> Spec.Spec Unit
38+describe name mkCtx body = FullSpec.describe name do
39+ FullSpec.before mkCtx body
41+it :: forall ctx. String -> Om ctx () Unit -> SpecOm ctx Unit
42+it name om = FullSpec.it name \ctx ->
43+ Om.runOm ctx { exception: mempty } om
45+itWith :: forall ctx ctx'. String -> Aff ctx' -> Om ctx' () Unit -> SpecOm ctx Unit
46+itWith name mkCtx om = FullSpec.it name \_ -> do
48+ Om.runOm ctx' { exception: mempty } om
50+fail :: forall m. MonadEffect m => String -> m Unit
51+fail = liftEffect <<< Exception.throwException <<< Exception.error
53+shouldEqual :: forall m t. MonadEffect m => Show t => Eq t => t -> t -> m Unit
54+shouldEqual v1 v2 = when (v1 /= v2) $ fail $ show v1 <> " ≠ " <> show v2
56+shouldNotEqual :: forall m t. MonadEffect m => Show t => Eq t => t -> t -> m Unit
57+shouldNotEqual v1 v2 = when (v1 == v2) $ fail $ show v1 <> " = " <> show v2
59+shouldSatisfy :: forall m t. MonadEffect m => Show t => t -> (t -> Boolean) -> m Unit
60+shouldSatisfy v pred = unless (pred v) $ fail $ show v <> " does not satisfy predicate"
62+shouldNotSatisfy :: forall m t. MonadEffect m => Show t => t -> (t -> Boolean) -> m Unit
63+shouldNotSatisfy v pred = when (pred v) $ fail $ show v <> " satisfies predicate"
65+shouldContain :: forall m f a. MonadEffect m => Show a => Eq a => Show (f a) => Foldable f => f a -> a -> m Unit
66+shouldContain c e = when (e `notElem` c) $ fail $ show e <> " ∉ " <> show c
68+shouldNotContain :: forall m f a. MonadEffect m => Show a => Eq a => Show (f a) => Foldable f => f a -> a -> m Unit
69+shouldNotContain c e = when (e `elem` c) $ fail $ show e <> " ∈ " <> show c
71+textContentShouldEqual :: forall m. MonadEffect m => HTMLElement -> String -> m Unit
72+textContentShouldEqual elem str = do
73+ content <- liftEffect $ textContent (HTMLElement.toNode elem)
74+ content `shouldEqual` str