You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Testing the init function](#testing-the-init-function)
31
33
-[Testing the update handler](#testing-the-update-handler)
32
34
-[Combine update and execCmd](#combine-update-and-execcmd)
@@ -456,6 +458,58 @@ function subscription (model: Model): SubscriptionResult<Message> {
456
458
457
459
The destructor is called when the component is removed from the DOM.
458
460
461
+
## Immutability
462
+
463
+
If you want to use immutable data structures, you can use the imports from "react-elmish/immutable". This version of the `useElmish` hook returns an immutable model.
// This will not update the model but only dispatch a command
499
+
return [cmd.ofMsg(Msg.increment())];
500
+
},
501
+
502
+
doNothing() {
503
+
// This does nothing
504
+
return [];
505
+
},
506
+
};
507
+
```
508
+
509
+
### Testing
510
+
511
+
If you want to test your component with immutable data structures, you can use the `react-elmish/testing/immutable` module. This module provides the same functions as the normal testing module.
512
+
459
513
## Setup
460
514
461
515
**react-elmish** works without a setup. But if you want to use logging or some middleware, you can setup **react-elmish** at the start of your program.
@@ -992,7 +1046,7 @@ It also resolves for `attempt` functions if the called functions succeed. And it
992
1046
There is an alternative function `getUpdateAndExecCmdFn` to get the `update` function for an update map, which immediately invokes the command and returns the messages.
It is almost the same as testing the `update` function. You can use the `getCreateModelAndProps` function to create a factory for the model and the props. Then use `execSubscription` to execute the subscriptions:
To test UI components with a fake model you can use `renderWithModel` from the Testing namespace. The first parameter is a function to render your component (e.g. with **@testing-library/react**). The second parameter is the fake model. The third parameter is an optional options object, where you can also pass a fake `dispatch` function.
0 commit comments