Module

Elmish.Enzyme.Foreign

Package
purescript-elmish-enzyme
Repository
collegevine/purescript-elmish-enzyme

Provides an FFI bindings for the Enzyme library. This is a pretty thin wrapper around Enzyme with a few convenience functions added. For a convenient API, use Elmish.Enzyme instead.

#NodeMultiplicity Source

#configure Source

configure :: Adapter -> Effect Unit

Configures the correct Enzyme adapter. Called once in the main spec.

#mount Source

mount :: forall m. MonadEffect m => ReactElement -> m (Wrapper SingleNode)

Fully mounts a ReactElement and returns a Wrapper. See https://enzymejs.github.io/enzyme/docs/api/shallow.html for more info.

#mountComponent Source

mountComponent :: forall m msg state. MonadAff m => ComponentDef msg state -> m (Wrapper SingleNode)

A convenience function for creating a full wrapper from a ComponentDef rather than a ReactElement. This also adds a delay (Milliseconds 0.0) to allow any effects in def.init to run.

#at Source

at :: forall m. MonadEffect m => Int -> Wrapper ManyNodes -> m (Wrapper SingleNode)

A Wrapper can wrap multiple DOM nodes. This function returns the node at the given index. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/at.html for more info.

#childAt Source

childAt :: forall m n. MonadEffect m => Int -> Wrapper n -> m (Wrapper SingleNode)

Returns the child node at index idx of the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/childAt.html ffor more info.

#children Source

children :: forall m n. MonadEffect m => Wrapper n -> m (Wrapper ManyNodes)

Returns the child nodes of the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/children.html ffor more info.

#count Source

count :: forall m n. MonadEffect m => String -> Wrapper n -> m Int

Returns the number of times a given selector appears within a wrapper.

#debug Source

debug :: forall m n. MonadEffect m => Wrapper n -> m String

Prints the shallow DOM tree up to any nested React components. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/debug.html for more info.

#exists Source

exists :: forall m n. MonadEffect m => String -> Wrapper n -> m Boolean

Returns a Boolean indicating whether a given selector exists within the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/exists.html for more info.

#find Source

find :: forall m n. MonadEffect m => String -> Wrapper n -> m (Wrapper ManyNodes)

Finds all elements with the given selector within the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/find.html for more info.

#forEach Source

forEach :: forall m. MonadEffect m => (Wrapper SingleNode -> m Unit) -> Wrapper ManyNodes -> m Unit

Runs the given action for every element contained in the given Wrapper as an array.

#is Source

is :: forall m. MonadEffect m => String -> (Wrapper SingleNode) -> m Boolean

Returns a Boolean indicating whether the given Wrapper matches the given selector. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/is.html for more info.

#length Source

length :: Wrapper ManyNodes -> Int

Returns number of elements in a given wrapper

#name Source

name :: forall m. MonadEffect m => Wrapper SingleNode -> m String

Returns tag name of the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/name.html for more info.

#parent Source

parent :: forall m n. MonadEffect m => Wrapper n -> m (Wrapper n)

Returns parent of the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/parent.html for more info.

#prop Source

prop :: forall a m. MonadEffect m => String -> Wrapper SingleNode -> m a

Returns the value of a Wrapper’s prop with a certain key. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/prop.html for more info.

#simulate Source

simulate :: forall m. MonadEffect m => String -> Wrapper SingleNode -> m Unit

A convenience function for calling simulate' without an event arg.

#simulate' Source

simulate' :: forall m r. MonadEffect m => String -> Record r -> Wrapper SingleNode -> m Unit

Simulates a certain event type on a given Wrapper. The event argument is a record that gets merged with a simulated React synthetic event before being passed to the component’s event handler. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/simulate.html for more info. NOTE: This doesn’t actually emit an event, but just triggers the event handler on the wrapper.

NOTE 2: This function only works for native HTML elements. For emitting events on custom React components, use simulateCustom.

#simulateCustom' Source

simulateCustom' :: forall m a. MonadEffect m => String -> a -> Wrapper SingleNode -> m Unit

Simulates an event on a custom React component (i.e. not an HTML element). For reasons to complicated to discuss here, the regular simulate doesn't work on custom components, so we provide this workaround.

NOTE: the second parameter is passed to the event handler without any checks whatsoever. This is, of course, not type-safe, but it is in line with what the event handler should expect anyway: after all, the underlying JavaScript component may pass anything at all as event argument.

#state Source

state :: forall m. MonadEffect m => Wrapper SingleNode -> m Foreign

Returns the state of the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/state.html for more info.

#text Source

text :: forall m. MonadEffect m => Wrapper SingleNode -> m String

Returns the text within the given Wrapper. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/text.html for more info.

#toArray Source

toArray :: forall m. MonadEffect m => Wrapper ManyNodes -> m (Array (Wrapper SingleNode))

Returns all elements contained in the given Wrapper as an array.

#unmount Source

unmount :: forall m. MonadEffect m => Wrapper SingleNode -> m Unit

Unmounts a fully mounted component. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/unmount.html for more info.

#unsafeSetState Source

unsafeSetState :: forall state m. MonadAff m => state -> Wrapper SingleNode -> m Unit

Sets the state of the given Wrapper. This is asynchronous, so runs in a MonadAff. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/setState.html for more info.

NOTE: this is a type-unsafe operation. There is no check to make sure the state being set here has the type of the actual state the component in question is using.

#update Source

update :: forall m n. MonadEffect m => Wrapper n -> m Unit

Updates the given Wrapper to reflect the latest state. Call this function whenever you think there could be an async change of state that caused a re-render. For some reason, Enzyme won't pick up the changes automatically. See https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/update.html for more info.