git.fiddlerwoaroof.com
Browse code

Merge pull request #2 from robrichard/master

pass additional props from ActionLink to a element

Ed Langley authored on 09/07/2017 00:34:02
Showing 3 changed files
... ...
@@ -1,5 +1,15 @@
1 1
 // Jest Snapshot v1, https://goo.gl/fbAQLP
2 2
 
3
+exports[`additional props are passed through 1`] = `
4
+<a
5
+  className="foo"
6
+  href="/my/path"
7
+  onClick={[Function]}
8
+>
9
+  Hello World!
10
+</a>
11
+`;
12
+
3 13
 exports[`renders the url calculated by our internal function 1`] = `
4 14
 <a
5 15
   href="/my/path"
... ...
@@ -1,7 +1,7 @@
1 1
 // Ugly way to deal with optional dependency so we don't break projects not using react.
2 2
 let React = null;
3 3
 
4
-const ActionLink = ({action, children}, {store}) => {
4
+const ActionLink = ({action, children, ...props}, {store}) => {
5 5
 
6 6
 
7 7
   if (!React) {
... ...
@@ -19,7 +19,8 @@ const ActionLink = ({action, children}, {store}) => {
19 19
        onClick={ev => {
20 20
          ev.preventDefault();
21 21
          store.dispatch(action);
22
-       }}>{children}</a>
22
+       }}
23
+       {...props}>{children}</a>
23 24
   );
24 25
 };
25 26
 
... ...
@@ -43,3 +43,22 @@ it("renders the url calculated by our internal function", () => {
43 43
   expect(ezJson(wrapper)).toMatchSnapshot();
44 44
 
45 45
 });
46
+
47
+it("additional props are passed through", () => {
48
+  // given
49
+  const store = {
50
+    pathForAction: jest.fn(() => '/my/path'),
51
+    dispatch: jest.fn()
52
+  };
53
+  const props = {
54
+    action: {},
55
+    children: "Hello World!",
56
+    className: "foo"
57
+  };
58
+  const context = {store};
59
+
60
+  const wrapper = mount(ActionLink(props, context));
61
+
62
+  expect(ezJson(wrapper)).toMatchSnapshot();
63
+
64
+});