Skip to content

Commit

Permalink
Failing test for alexmingoia#132
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatsushita committed Jun 27, 2017
1 parent 415e921 commit ba0add1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
38 changes: 35 additions & 3 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -86,3 +86,35 @@ main = runTest do
rendered <- renderToStaticMarkup component.markup
pure rendered
equal """<ul></ul>""" 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 """<div data="true"><li>1</li></div>""" 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 """<div data="true"><li>1</li><li>2</li></div>""" result
6 changes: 6 additions & 0 deletions test/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions test/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit ba0add1

Please sign in to comment.