@mittwald/react-ghostmaker 1.4.1 → 1.4.2

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.
@@ -9,11 +9,14 @@ export function asGhost(maybeGhost) {
9
9
  export function asGhostProps(props, keys) {
10
10
  const fixupObjectEntry = (entry) => {
11
11
  const [key, value] = entry;
12
+ if (value === undefined) {
13
+ return entry;
14
+ }
12
15
  const shouldFixup = keys === undefined || keys.includes(key);
13
16
  if (shouldFixup) {
14
17
  return [`${key}Ghost`, asGhost(value)];
15
18
  }
16
- return [key, value];
19
+ return entry;
17
20
  };
18
21
  return Object.fromEntries(Object.entries(props).map(fixupObjectEntry));
19
22
  }
@@ -0,0 +1,42 @@
1
+ import { asGhostProps } from "../maybeGhost";
2
+ import { isReactGhost } from "../types";
3
+ import { expect, test } from "vitest";
4
+ test("makes Ghosts of all props", () => {
5
+ const ghostProps = asGhostProps({
6
+ first: "hello",
7
+ second: "world",
8
+ third: "!",
9
+ });
10
+ expect(ghostProps.firstGhost).toSatisfy(isReactGhost);
11
+ expect(ghostProps.secondGhost).toSatisfy(isReactGhost);
12
+ expect(ghostProps.thirdGhost).toSatisfy(isReactGhost);
13
+ });
14
+ test("does not make Ghosts of explicit undefined", () => {
15
+ const ghostProps = asGhostProps({
16
+ first: "hello",
17
+ second: undefined,
18
+ third: "!",
19
+ });
20
+ expect(ghostProps.firstGhost).toSatisfy(isReactGhost);
21
+ expect(ghostProps.secondGhost).toBeUndefined();
22
+ expect(ghostProps.thirdGhost).toSatisfy(isReactGhost);
23
+ });
24
+ test("does not make Ghosts of not given props", () => {
25
+ const ghostProps = asGhostProps({
26
+ first: "hello",
27
+ third: "!",
28
+ });
29
+ expect(ghostProps.firstGhost).toSatisfy(isReactGhost);
30
+ expect(ghostProps.secondGhost).toBeUndefined();
31
+ expect(ghostProps.thirdGhost).toSatisfy(isReactGhost);
32
+ });
33
+ test("does not make Ghosts of excluded props", () => {
34
+ const ghostProps = asGhostProps({
35
+ first: "hello",
36
+ second: "world",
37
+ third: "!",
38
+ }, ["first"]);
39
+ expect(ghostProps.firstGhost).toSatisfy(isReactGhost);
40
+ expect(ghostProps.secondGhost).not.toSatisfy(isReactGhost);
41
+ expect(ghostProps.thirdGhost).not.toSatisfy(isReactGhost);
42
+ });
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-ghostmaker",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
5
5
  "contributors": [
6
6
  "Marco Falkenberg <m.falkenberg@mittwald.de>"