Skip to content

Commit ab80e53

Browse files
author
Matthew Toledo
committed
added a way to populate props
1 parent b1c1aae commit ab80e53

File tree

3 files changed

+113
-8
lines changed

3 files changed

+113
-8
lines changed

dist/react-router-enzyme-context.cjs.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,36 +1504,71 @@ var _createClass = function () { function defineProperties(target, props) { for
15041504
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15051505

15061506
var ReactRouterEnzymeContext = function () {
1507-
function ReactRouterEnzymeContext() {
1507+
function ReactRouterEnzymeContext(options) {
15081508
_classCallCheck(this, ReactRouterEnzymeContext);
15091509

1510+
var defaults = {
1511+
initialEntries: ['/'],
1512+
initialIndex: 0,
1513+
keyLength: 6,
1514+
getUserConfirmation: null
1515+
};
1516+
15101517
this.context = {
15111518
router: {
1512-
history: createHistory()
1519+
history: createHistory(Object.assign({}, defaults, options))
15131520
}
15141521
};
15151522

1523+
this.context.router.route = {
1524+
location: this.context.router.history.location
1525+
};
1526+
15161527
this.childContextTypes = {
1528+
route: propTypes.shape({
1529+
pathName: propTypes.string,
1530+
search: propTypes.string,
1531+
hash: propTypes.hash,
1532+
state: propTypes.any,
1533+
key: propTypes.string
1534+
}),
15171535
router: propTypes.shape({
15181536
history: propTypes.shape({
15191537
length: propTypes.number,
1538+
action: propTypes.string,
15201539
location: propTypes.shape({
15211540
pathName: propTypes.string,
15221541
search: propTypes.string,
15231542
hash: propTypes.hash,
15241543
state: propTypes.any,
15251544
key: propTypes.string
15261545
}),
1546+
index: propTypes.number,
1547+
entries: propTypes.arrayOf(propTypes.shape({
1548+
pathName: propTypes.string,
1549+
search: propTypes.string,
1550+
hash: propTypes.hash,
1551+
state: propTypes.any,
1552+
key: propTypes.string
1553+
})),
15271554
push: propTypes.func,
15281555
replace: propTypes.func,
15291556
go: propTypes.func,
15301557
goBack: propTypes.func,
15311558
goForward: propTypes.func,
15321559
canGo: propTypes.func,
1533-
block: propTypes.func
1560+
block: propTypes.func,
1561+
listen: propTypes.func
15341562
})
15351563
})
15361564
};
1565+
1566+
this.history = this.context.router.history;
1567+
1568+
this.get = this.get.bind(this);
1569+
this.getChildContextTypes = this.getChildContextTypes.bind(this);
1570+
this.getContext = this.getContext.bind(this);
1571+
this.props = this.props.bind(this);
15371572
}
15381573

15391574
_createClass(ReactRouterEnzymeContext, [{

dist/react-router-enzyme-context.esm.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,36 +1502,71 @@ var _createClass = function () { function defineProperties(target, props) { for
15021502
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15031503

15041504
var ReactRouterEnzymeContext = function () {
1505-
function ReactRouterEnzymeContext() {
1505+
function ReactRouterEnzymeContext(options) {
15061506
_classCallCheck(this, ReactRouterEnzymeContext);
15071507

1508+
var defaults = {
1509+
initialEntries: ['/'],
1510+
initialIndex: 0,
1511+
keyLength: 6,
1512+
getUserConfirmation: null
1513+
};
1514+
15081515
this.context = {
15091516
router: {
1510-
history: createHistory()
1517+
history: createHistory(Object.assign({}, defaults, options))
15111518
}
15121519
};
15131520

1521+
this.context.router.route = {
1522+
location: this.context.router.history.location
1523+
};
1524+
15141525
this.childContextTypes = {
1526+
route: propTypes.shape({
1527+
pathName: propTypes.string,
1528+
search: propTypes.string,
1529+
hash: propTypes.hash,
1530+
state: propTypes.any,
1531+
key: propTypes.string
1532+
}),
15151533
router: propTypes.shape({
15161534
history: propTypes.shape({
15171535
length: propTypes.number,
1536+
action: propTypes.string,
15181537
location: propTypes.shape({
15191538
pathName: propTypes.string,
15201539
search: propTypes.string,
15211540
hash: propTypes.hash,
15221541
state: propTypes.any,
15231542
key: propTypes.string
15241543
}),
1544+
index: propTypes.number,
1545+
entries: propTypes.arrayOf(propTypes.shape({
1546+
pathName: propTypes.string,
1547+
search: propTypes.string,
1548+
hash: propTypes.hash,
1549+
state: propTypes.any,
1550+
key: propTypes.string
1551+
})),
15251552
push: propTypes.func,
15261553
replace: propTypes.func,
15271554
go: propTypes.func,
15281555
goBack: propTypes.func,
15291556
goForward: propTypes.func,
15301557
canGo: propTypes.func,
1531-
block: propTypes.func
1558+
block: propTypes.func,
1559+
listen: propTypes.func
15321560
})
15331561
})
15341562
};
1563+
1564+
this.history = this.context.router.history;
1565+
1566+
this.get = this.get.bind(this);
1567+
this.getChildContextTypes = this.getChildContextTypes.bind(this);
1568+
this.getContext = this.getContext.bind(this);
1569+
this.props = this.props.bind(this);
15351570
}
15361571

15371572
_createClass(ReactRouterEnzymeContext, [{

src/index.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,69 @@ import createHistory from 'history/createMemoryHistory';
22
import PropTypes from 'prop-types';
33

44
export default class ReactRouterEnzymeContext {
5-
constructor() {
5+
constructor(options) {
6+
const defaults = {
7+
initialEntries: ['/'],
8+
initialIndex: 0,
9+
keyLength: 6,
10+
getUserConfirmation: null,
11+
};
12+
613
this.context = {
714
router: {
8-
history: createHistory(),
15+
history: createHistory(Object.assign({}, defaults, options)),
916
},
1017
};
1118

19+
this.context.router.route = {
20+
location: this.context.router.history.location,
21+
};
22+
1223
this.childContextTypes = {
24+
route: PropTypes.shape({
25+
pathName: PropTypes.string,
26+
search: PropTypes.string,
27+
hash: PropTypes.hash,
28+
state: PropTypes.any,
29+
key: PropTypes.string,
30+
}),
1331
router: PropTypes.shape({
1432
history: PropTypes.shape({
1533
length: PropTypes.number,
34+
action: PropTypes.string,
1635
location: PropTypes.shape({
1736
pathName: PropTypes.string,
1837
search: PropTypes.string,
1938
hash: PropTypes.hash,
2039
state: PropTypes.any,
2140
key: PropTypes.string,
2241
}),
42+
index: PropTypes.number,
43+
entries: PropTypes.arrayOf(PropTypes.shape({
44+
pathName: PropTypes.string,
45+
search: PropTypes.string,
46+
hash: PropTypes.hash,
47+
state: PropTypes.any,
48+
key: PropTypes.string,
49+
})),
2350
push: PropTypes.func,
2451
replace: PropTypes.func,
2552
go: PropTypes.func,
2653
goBack: PropTypes.func,
2754
goForward: PropTypes.func,
2855
canGo: PropTypes.func,
2956
block: PropTypes.func,
57+
listen: PropTypes.func,
3058
}),
3159
}),
3260
};
61+
62+
this.history = this.context.router.history;
63+
64+
this.get = this.get.bind(this);
65+
this.getChildContextTypes = this.getChildContextTypes.bind(this);
66+
this.getContext = this.getContext.bind(this);
67+
this.props = this.props.bind(this);
3368
}
3469

3570
getContext() {

0 commit comments

Comments
 (0)