@@ -0,0 +1,74 @@
1+module Yoga.Om.Test
2+ ( describe
3+ , it
4+ , itWith
5+ , testOm
6+ , fail
7+ , shouldEqual
8+ , shouldNotEqual
9+ , shouldSatisfy
10+ , shouldNotSatisfy
11+ , shouldContain
12+ , shouldNotContain
13+ , textContentShouldEqual
14+ , module Spec
15+ ) where
16+
17+import Prelude
18+
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
29+import Yoga.Om (Om)
30+import Yoga.Om as Om
31+
32+type SpecOm ctx a = Spec.SpecT Aff ctx Identity a
33+
34+testOm :: forall ctx a. Monoid a => ctx -> Om ctx () a -> Aff a
35+testOm ctx = Om.runOm ctx { exception: mempty }
36+
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
40+
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
44+
45+itWith :: forall ctx ctx'. String -> Aff ctx' -> Om ctx' () Unit -> SpecOm ctx Unit
46+itWith name mkCtx om = FullSpec.it name \_ -> do
47+ ctx' <- mkCtx
48+ Om.runOm ctx' { exception: mempty } om
49+
50+fail :: forall m. MonadEffect m => String -> m Unit
51+fail = liftEffect <<< Exception.throwException <<< Exception.error
52+
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
55+
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
58+
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"
61+
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"
64+
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
67+
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
70+
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