git.iko.soy/rowtype-yoga/purescript-spec-om
on main help sign in
spec-om v0.1.0
a4b1940Mark
.gitignorenew file+6
@@ -0,0 +1,6 @@
1+node_modules/
2+.spago/
3+output/
4+.psci_modules/
5+.psc-ide-port
6+.DS_Store
LICENSEnew file+21
@@ -0,0 +1,21 @@
1+MIT License
2+
3+Copyright (c) 2026 Mark Eibes
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+
12+The above copyright notice and this permission notice shall be included in all
13+copies or substantial portions of the Software.
14+
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+SOFTWARE.
spago.yamlnew file+19
@@ -0,0 +1,19 @@
1+package:
2+ name: spec-om
3+ publish:
4+ version: 0.1.0
5+ license: MIT
6+ location:
7+ githubOwner: rowtype-yoga
8+ githubRepo: purescript-spec-om
9+ dependencies:
10+ - aff: ">=7.0.0 <8.0.0"
11+ - effect: ">=4.0.0 <5.0.0"
12+ - exceptions: ">=6.0.0 <7.0.0"
13+ - foldable-traversable: ">=6.0.0 <7.0.0"
14+ - identity: ">=6.0.0 <7.0.0"
15+ - prelude: ">=6.0.0 <7.0.0"
16+ - spec: ">=8.0.0 <9.0.0"
17+ - web-dom: ">=6.0.0 <7.0.0"
18+ - web-html: ">=4.0.0 <5.0.0"
19+ - yoga-om: ">=1.2.2 <2.0.0"
src/Yoga/Om/Test.pursnew file+74
@@ -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