From ba0add184814a141cc3634c148c059c8f93736bf Mon Sep 17 00:00:00 2001 From: Jun Matsushita Date: Tue, 27 Jun 2017 21:57:27 +0200 Subject: [PATCH] Failing test for #132 --- test/Main.purs | 38 +++++++++++++++++++++++++++++++++++--- test/React.js | 6 ++++++ test/React.purs | 5 +++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index de594e2..4dfa4d4 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,7 +2,7 @@ module Test.Main where import Prelude hiding (div) -import Data.Monoid (mempty) +import Data.Monoid(mempty) import Control.Monad.Aff.AVar (AVAR) import Control.Monad.Eff (Eff) @@ -15,11 +15,11 @@ import Test.Unit (test) import Test.Unit.Assert (equal) import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) -import Text.Smolder.HTML (div) import Text.Smolder.HTML (div, li) import Text.Smolder.Markup (text, (!)) -import Test.React (list) +import Test.React (list, childrenIsArray) + data Event = Noop type TestEffects = (console :: CONSOLE, testOutput :: TESTOUTPUT, avar:: AVAR) @@ -86,3 +86,35 @@ main = runTest do rendered <- renderToStaticMarkup component.markup pure rendered equal """""" result + + + test "passes children props as array for a single child" $ do + result <- liftEff $ do + let foldp Noop st = { state: st, effects: []} + view _ = childrenIsArray $ do + li $ text "1" + component <- start + { initialState: 0 + , view + , foldp + , inputs: [] + } + rendered <- renderToStaticMarkup component.markup + pure rendered + equal """
  • 1
  • """ result + + test "passes children props as array for a two children" $ do + result <- liftEff $ do + let foldp Noop st = { state: st, effects: []} + view _ = childrenIsArray $ do + li $ text "1" + li $ text "2" + component <- start + { initialState: 0 + , view + , foldp + , inputs: [] + } + rendered <- renderToStaticMarkup component.markup + pure rendered + equal """
  • 1
  • 2
  • """ result diff --git a/test/React.js b/test/React.js index 459997f..1208798 100644 --- a/test/React.js +++ b/test/React.js @@ -7,4 +7,10 @@ function list(props) { return React.createElement('ul', null, children); } +function childrenIsArray(props) { + var children = props.children; + return React.createElement('div', { data: JSON.stringify(Array.isArray(children)) }, children); +} + exports.listComponent = list; +exports.childrenisArrayFn = childrenIsArray; diff --git a/test/React.purs b/test/React.purs index 0a8266e..70e2076 100644 --- a/test/React.purs +++ b/test/React.purs @@ -6,5 +6,10 @@ import Pux.DOM.HTML (HTML) import Pux.Renderer.React (reactClass) foreign import listComponent :: ∀ props. ReactClass props +foreign import childrenisArrayFn :: ∀ props. ReactClass props + list :: ∀ ev. HTML ev -> HTML ev list = reactClass listComponent "list" + +childrenIsArray :: ∀ ev. HTML ev -> HTML ev +childrenIsArray = reactClass childrenisArrayFn "isArray"