react-elmish 6.6.3 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -851,17 +851,19 @@ To test your **update** handler you can use some helper functions in `react-elmi
|
|
|
851
851
|
|
|
852
852
|
| Function | Description |
|
|
853
853
|
| --- | --- |
|
|
854
|
-
| `execCmd` | Executes the provided command and returns an array of all messages. |
|
|
855
854
|
| `initAndExecCmd` | Calls the `init` function with the provided props and executes the returned commands. |
|
|
856
855
|
| `getUpdateFn` | Returns an `update` function for your update map object. |
|
|
857
856
|
| `getUpdateAndExecCmdFn` | Returns an `update` function for your update map object, which immediately executes the command. |
|
|
858
|
-
| `
|
|
857
|
+
| `getCreateUpdateArgs` | Creates a factory function to create a message, a model, and props in a test. |
|
|
858
|
+
| `createUpdateArgsFactory` | This is an alternative for `getCreateUpdateArgs`. Creates a factory function to create a message, a model, and props in a test. |
|
|
859
|
+
| `execCmd` | Executes the provided command and returns an array of all messages. |
|
|
859
860
|
| `getOfMsgParams` | Extracts the messages out of a command. You should not use this function, because its likely to be deprecated in near future. Use `execCmd` instead. |
|
|
860
861
|
|
|
861
862
|
### Testing the init function
|
|
862
863
|
|
|
863
864
|
```ts
|
|
864
865
|
import { initAndExecCmd } from "react-elmish/dist/Testing";
|
|
866
|
+
import { init, Msg } from "./MyComponent";
|
|
865
867
|
|
|
866
868
|
it("initializes the model correctly", async () => {
|
|
867
869
|
// arrange
|
|
@@ -882,6 +884,7 @@ it("initializes the model correctly", async () => {
|
|
|
882
884
|
|
|
883
885
|
```ts
|
|
884
886
|
import { getUpdateFn } from "react-elmish/dist/Testing";
|
|
887
|
+
import { updateMap } from "./MyComponent";
|
|
885
888
|
|
|
886
889
|
const updateFn = getUpdateFn(updateMap);
|
|
887
890
|
|
|
@@ -892,11 +895,12 @@ const [model, cmd] = updateFn(msg, model, props);
|
|
|
892
895
|
A simple test:
|
|
893
896
|
|
|
894
897
|
```ts
|
|
895
|
-
import { createUpdateArgsFactory, execCmd } from "react-elmish/dist/Testing";
|
|
898
|
+
import { getCreateUpdateArgs, createUpdateArgsFactory, execCmd } from "react-elmish/dist/Testing";
|
|
899
|
+
import { init, Msg } from "./MyComponent";
|
|
896
900
|
|
|
897
|
-
const createUpdateArgs =
|
|
901
|
+
const createUpdateArgs = getCreateUpdateArgs(init, () => ({ /* initial props */ }));
|
|
902
|
+
// Or: const createUpdateArgs = createUpdateArgsFactory(() => ({ /* initial model */ }), () => ({ /* initial props */ }));
|
|
898
903
|
|
|
899
|
-
...
|
|
900
904
|
it("returns the correct model and cmd", async () => {
|
|
901
905
|
// arrange
|
|
902
906
|
const args = createUpdateArgs(Msg.test(), { /* optionally override model here */ }, { /* optionally override props here */ });
|
|
@@ -913,7 +917,6 @@ it("returns the correct model and cmd", async () => {
|
|
|
913
917
|
Msg.expectedMsg2(),
|
|
914
918
|
]);
|
|
915
919
|
});
|
|
916
|
-
...
|
|
917
920
|
```
|
|
918
921
|
|
|
919
922
|
With `execCmd` you can execute all commands in a test scenario. All functions are called and awaited. The function returns all new messages (success or error messages).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { InitFunction, Message } from "../Types";
|
|
2
|
+
import { UpdateArgsFactory } from "./createUpdateArgsFactory";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a factory function to create a message, a model, and props which can be passed to an update function in tests.
|
|
5
|
+
* @param {InitFunction<TProps, TModel, TMessage>} init The init function which creates the model.
|
|
6
|
+
* @param {() => TProps} initProps A function to create initial props.
|
|
7
|
+
* @returns {UpdateArgsFactory<TProps, TModel, TMessage>} A function to create a message, a model, and props.
|
|
8
|
+
* @example
|
|
9
|
+
* // one time
|
|
10
|
+
* const createUpdateArgs = getCreateUpdateArgs(init, () => ({ ... }));
|
|
11
|
+
* // in tests
|
|
12
|
+
* const [msg, model, props] = createUpdateArgs(Msg.myMessage(), { ... }, , { ... });
|
|
13
|
+
*/
|
|
14
|
+
declare function getCreateUpdateArgs<TProps, TModel, TMessage extends Message>(init: InitFunction<TProps, TModel, TMessage>, initProps: () => TProps): UpdateArgsFactory<TProps, TModel, TMessage>;
|
|
15
|
+
export { getCreateUpdateArgs, };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getCreateUpdateArgs = getCreateUpdateArgs;
|
|
7
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
18
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
19
|
+
/**
|
|
20
|
+
* Creates a factory function to create a message, a model, and props which can be passed to an update function in tests.
|
|
21
|
+
* @param {InitFunction<TProps, TModel, TMessage>} init The init function which creates the model.
|
|
22
|
+
* @param {() => TProps} initProps A function to create initial props.
|
|
23
|
+
* @returns {UpdateArgsFactory<TProps, TModel, TMessage>} A function to create a message, a model, and props.
|
|
24
|
+
* @example
|
|
25
|
+
* // one time
|
|
26
|
+
* const createUpdateArgs = getCreateUpdateArgs(init, () => ({ ... }));
|
|
27
|
+
* // in tests
|
|
28
|
+
* const [msg, model, props] = createUpdateArgs(Msg.myMessage(), { ... }, , { ... });
|
|
29
|
+
*/
|
|
30
|
+
function getCreateUpdateArgs(init, initProps) {
|
|
31
|
+
return function (msg, modelTemplate, propsTemplate) {
|
|
32
|
+
var props = _objectSpread(_objectSpread({}, initProps()), propsTemplate);
|
|
33
|
+
var _init = init(props),
|
|
34
|
+
_init2 = _slicedToArray(_init, 1),
|
|
35
|
+
model = _init2[0];
|
|
36
|
+
return [msg, _objectSpread(_objectSpread({}, model), modelTemplate), props];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJnZXRDcmVhdGVVcGRhdGVBcmdzIiwiaW5pdCIsImluaXRQcm9wcyIsIm1zZyIsIm1vZGVsVGVtcGxhdGUiLCJwcm9wc1RlbXBsYXRlIiwicHJvcHMiLCJfb2JqZWN0U3ByZWFkIiwiX2luaXQiLCJfaW5pdDIiLCJfc2xpY2VkVG9BcnJheSIsIm1vZGVsIl0sInNvdXJjZXMiOlsiLi4vLi4vc3JjL1Rlc3RpbmcvZ2V0Q3JlYXRlVXBkYXRlQXJncy50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBJbml0RnVuY3Rpb24sIE1lc3NhZ2UgfSBmcm9tIFwiLi4vVHlwZXNcIjtcbmltcG9ydCB7IFVwZGF0ZUFyZ3NGYWN0b3J5IH0gZnJvbSBcIi4vY3JlYXRlVXBkYXRlQXJnc0ZhY3RvcnlcIjtcblxuLyoqXG4gKiBDcmVhdGVzIGEgZ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sY0FBQSxDQUFBRixLQUFBO01BQXBCRyxLQUFLLEdBQUFGLE1BQUE7SUFFWixPQUFPLENBQ0hOLEdBQUcsRUFBQUksYUFBQSxDQUFBQSxhQUFBLEtBRUlJLEtBQUssR0FDTFAsYUFBYSxHQUVwQkUsS0FBSyxDQUNSO0VBQ0wsQ0FBQztBQUNMIn0=
|
package/dist/Testing/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createUpdateArgsFactory, UpdateArgsFactory } from "./createUpdateArgsFactory";
|
|
2
2
|
import { execCmd } from "./execCmd";
|
|
3
3
|
import { RenderWithModelOptions } from "./fakeOptions";
|
|
4
|
+
import { getCreateUpdateArgs } from "./getCreateUpdateArgs";
|
|
4
5
|
import { getOfMsgParams } from "./getOfMsgParams";
|
|
5
6
|
import { getUpdateAndExecCmdFn, getUpdateFn } from "./getUpdateFn";
|
|
6
7
|
import { initAndExecCmd } from "./initAndExecCmd";
|
|
7
8
|
import { renderWithModel } from "./renderWithModel";
|
|
8
9
|
export type { UpdateArgsFactory, RenderWithModelOptions, };
|
|
9
|
-
export { getOfMsgParams, execCmd, initAndExecCmd, getUpdateFn, getUpdateAndExecCmdFn, createUpdateArgsFactory, renderWithModel, };
|
|
10
|
+
export { getOfMsgParams, execCmd, initAndExecCmd, getUpdateFn, getUpdateAndExecCmdFn, createUpdateArgsFactory, getCreateUpdateArgs, renderWithModel, };
|
package/dist/Testing/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "execCmd", {
|
|
|
15
15
|
return _execCmd.execCmd;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "getCreateUpdateArgs", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _getCreateUpdateArgs.getCreateUpdateArgs;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "getOfMsgParams", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function get() {
|
|
@@ -47,8 +53,9 @@ Object.defineProperty(exports, "renderWithModel", {
|
|
|
47
53
|
});
|
|
48
54
|
var _createUpdateArgsFactory = require("./createUpdateArgsFactory");
|
|
49
55
|
var _execCmd = require("./execCmd");
|
|
56
|
+
var _getCreateUpdateArgs = require("./getCreateUpdateArgs");
|
|
50
57
|
var _getOfMsgParams = require("./getOfMsgParams");
|
|
51
58
|
var _getUpdateFn = require("./getUpdateFn");
|
|
52
59
|
var _initAndExecCmd = require("./initAndExecCmd");
|
|
53
60
|
var _renderWithModel = require("./renderWithModel");
|
|
54
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
61
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfY3JlYXRlVXBkYXRlQXJnc0ZhY3RvcnkiLCJyZXF1aXJlIiwiX2V4ZWNDbWQiLCJfZ2V0Q3JlYXRlVXBkYXRlQXJncyIsIl9nZXRPZk1zZ1BhcmFtcyIsIl9nZXRVcGRhdGVGbiIsIl9pbml0QW5kRXhlY0NtZCIsIl9yZW5kZXJXaXRoTW9kZWwiXSwic291cmNlcyI6WyIuLi8uLi9zcmMvVGVzdGluZy9pbmRleC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBjcmVhdGVVcGRhdGVBcmdzRmFjdG9yeSwgVXBkYXRlQXJnc0ZhY3RvcnkgfSBmcm9tIFwiLi9jcmVhdGVVcGRhdGVBcmdzRmFjdG9yeVwiO1xuaW1wb3J0IHsgZXhlY0NtZCB9IGZyb20gXCIuL2V4ZWNDbWRcIjtcbmltcG9ydCB7IFJlbmRlcldpdGhNb2RlbE9wdGlvbnMgfSBmcm9tIFwiLi9mYWtlT3B0aW9uc1wiO1xuaW1wb3J0IHsgZ2V0Q3JlYXRlVXBkYXRlQXJncyB9IGZyb20gXCIuL2dldENyZWF0ZVVwZGF0ZUFyZ3NcIjtcbmltcG9yd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