git.fiddlerwoaroof.com
Browse code

Merge branch 'master' into doc-example

Ed Langley authored on 18/06/2017 03:13:17
Showing 1 changed files
... ...
@@ -1,6 +1,8 @@
1 1
 import {applyMiddleware, createStore, compose} from 'redux';
2 2
 
3 3
 import installBrowserRouter from './action-router';
4
+import addChangeUrlEvent from './change-url-event.js';
5
+import addMissingHistoryEvents from './history-events.js';
4 6
 
5 7
 function createLocation(path) {
6 8
   return {
... ...
@@ -43,24 +45,32 @@ function createFakeWindow(path='/path/to/thing') {
43 45
 function setupTest(routesConfig, path='/path/to/thing') {
44 46
   const window = createFakeWindow(path);
45 47
   const mockPushState = window.history.pushState;
48
+  addMissingHistoryEvents(window, window.history);
49
+  addChangeUrlEvent(window, window.history);
46 50
 
47 51
   const {middleware, enhancer} = installBrowserRouter(routesConfig, window);
48
-  const reduce = jest.fn();
49
-  const store = createStore(reduce, compose(enhancer, applyMiddleware(middleware)));
52
+    const reduce = jest.fn();
50 53
 
51
-  function urlChanges() {
52
-    return mockPushState.mock.calls.map(item => item[2]);
53
-  }
54
+    const store = createStore(
55
+      reduce,
56
+      compose(
57
+        enhancer,
58
+        applyMiddleware(
59
+          middleware)));
54 60
 
55
-  function actionsDispatched() {
56
-    return reduce.mock.calls.map(item => item[1]).slice(1);
57
-  }
61
+    function urlChanges() {
62
+      return mockPushState.mock.calls.map(item => item[2]);
63
+    }
64
+
65
+    function actionsDispatched() {
66
+      return reduce.mock.calls.map(item => item[1]).slice(1);
67
+    }
58 68
 
59
-  function fireUrlChange(path) {
60
-    window.dispatchEvent(new CustomEvent('urlchanged', {detail: createLocation(path)}));
61
-  }
69
+    function fireUrlChange(path) {
70
+      window.dispatchEvent(new CustomEvent('urlchanged', {detail: createLocation(path)}));
71
+    }
62 72
 
63
-  return {store, reduce, window, urlChanges, actionsDispatched, fireUrlChange};
73
+    return {store, reduce, window, urlChanges, actionsDispatched, fireUrlChange};
64 74
 }
65 75
 
66 76
 it("router handles exact match in preference to wildcard match", () => {