diff --git a/test/helper.js b/test/helper.js
index 0a1bdeacb542..69c89ffb5927 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -35,6 +35,9 @@ require('jsdom-global')()
// localStorage
window.localStorage = {}
+// override metamask-logo
+window.requestAnimationFrame = () => {}
+
// crypto.getRandomValues
if (!window.crypto) {
window.crypto = {}
diff --git a/test/lib/render-helpers.js b/test/lib/render-helpers.js
index f2332826e357..07c84bc80105 100644
--- a/test/lib/render-helpers.js
+++ b/test/lib/render-helpers.js
@@ -1,19 +1,14 @@
const { shallow, mount } = require('enzyme')
+import sinon from 'sinon'
import React from 'react'
-import { BrowserRouter } from 'react-router-dom'
-import { shape } from 'prop-types'
+import { MemoryRouter } from 'react-router-dom'
+import PropTypes from 'prop-types'
module.exports = {
- shallowWithStore,
mountWithStore,
mountWithRouter,
-}
-
-function shallowWithStore (component, store) {
- const context = {
- store,
- }
- return shallow(component, { context })
+ shallowWithRouter,
+ stubComponent,
}
function mountWithStore (component, store) {
@@ -23,27 +18,101 @@ function mountWithStore (component, store) {
return mount(component, { context })
}
-function mountWithRouter (node) {
+function mountWithRouter (component, store, pathname) {
// Instantiate router context
const router = {
- history: new BrowserRouter().history,
+ history: new MemoryRouter().history,
route: {
- location: {},
+ location: {
+ pathname: pathname || '/',
+ },
match: {},
},
}
const createContext = () => ({
- context: { router, t: () => {} },
- childContextTypes: { router: shape({}), t: () => {} },
+ context: {
+ router,
+ t: str => str,
+ tOrKey: str => str,
+ metricsEvent: () => {},
+ store,
+ },
+ childContextTypes: {
+ router: PropTypes.object,
+ t: PropTypes.func,
+ tOrKey: PropTypes.func,
+ metricsEvent: PropTypes.func,
+ store: PropTypes.object,
+ },
})
const Wrapper = () => (
-
- {node}
-
+
+ {component}
+
)
return mount(, createContext())
}
+
+function shallowWithRouter (component, store, pathname) {
+
+ // Instantiate router context
+ const router = {
+ history: new MemoryRouter().history,
+ route: {
+ location: {
+ pathname: pathname || '/',
+ },
+ match: {},
+ },
+ }
+
+ const createContext = () => ({
+ context: {
+ router,
+ t: str => str,
+ tOrKey: str => str,
+ metricsEvent: () => {},
+ store,
+ },
+ childContextTypes: {
+ router: PropTypes.object,
+ t: PropTypes.func,
+ tOrKey: PropTypes.func,
+ metricsEvent: PropTypes.func,
+ store: PropTypes.object,
+ },
+ })
+
+ const Wrapper = () => (
+
+ {component}
+
+ )
+
+ return shallow(, createContext())
+}
+
+function stubComponent (componentClass) {
+
+ const lifecycleMethods = [
+ 'render',
+ 'componentWillMount',
+ 'componentDidMount',
+ 'componentWillReceiveProps',
+ 'shouldComponentUpdate',
+ 'componentWillUpdate',
+ 'componentDidUpdate',
+ 'componentWillUnmount',
+ ]
+
+ lifecycleMethods.forEach((method) => {
+ if (typeof componentClass.prototype[method] !== 'undefined') {
+ sinon.stub(componentClass.prototype, method).returns(null)
+ }
+ })
+
+}