Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
From b34d733deefac7fb7f96bf5408ae705c49e764fa Mon Sep 17 00:00:00 2001
From: Isaiah Peng <issaria@gmail.com>
Date: Fri, 4 Mar 2016 11:17:40 +0100
Subject: [PATCH 1/1] include jquery and materializecss for test
---
karma.conf.js | 2 ++
package.json | 2 ++
src/Select.js | 67 ++++++++++++++++++++++++++++++-----------------------------
3 files changed, 38 insertions(+), 33 deletions(-)
diff --git a/karma.conf.js b/karma.conf.js
index 0a03abf..875256b 100644
--- a/karma.conf.js
+++ b/karma.conf.js
@@ -16,6 +16,8 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
+ 'node_modules/jquery/dist/jquery.js',
+ 'node_modules/materializecss/src/ng2-materializecss.js',
'test/*Spec.js'
],
diff --git a/package.json b/package.json
index c7c72aa..8ed1e2b 100644
--- a/package.json
+++ b/package.json
@@ -45,6 +45,7 @@
"es5-shim": "^4.2.0",
"eslint": "^1.9.0",
"eslint-plugin-react": "^3.8.0",
+ "jquery": "^2.2.1",
"karma": "^0.13.15",
"karma-babel-preprocessor": "^6.0.1",
"karma-mocha": "^0.2.0",
@@ -52,6 +53,7 @@
"karma-sinon-chai": "^1.1.0",
"karma-sourcemap-loader": "^0.3.6",
"karma-webpack": "^1.7.0",
+ "materializecss": "^1.0.11",
"mocha": "^2.3.3",
"phantomjs": "^1.9.18",
"react": ">=0.14.0",
diff --git a/src/Select.js b/src/Select.js
index c21ded9..3c09a09 100644
--- a/src/Select.js
+++ b/src/Select.js
@@ -4,21 +4,6 @@ import constants from './constants';
class Select extends Component {
- static propTypes = {
- onChange: PropTypes.func.isRequired,
- children: PropTypes.node.isRequired,
- s: PropTypes.number,
- m: PropTypes.number,
- l: PropTypes.number,
- label: PropTypes.node,
- defaultValue: PropTypes.string,
- browserDefault: PropTypes.bool
- }
-
- static defaultProps = {
- browserDefault: false
- }
-
constructor(props) {
super(props);
this.state = { value: props.defaultValue };
@@ -52,30 +37,46 @@ class Select extends Component {
render() {
const { children, label, browserDefault } = this.props;
const classes = Object.assign(
- {},
- {
- 'input-field': true,
- 'col': true,
- 'browser-default': browserDefault
- },
- constants.SIZES.reduce((result, size) => {
- return this.props[size]
- ? Object.assign({}, result, { [size + this.props[size]]: true })
- : result;
- }, {})
- );
+ {},
+ {
+ 'input-field': true,
+ 'col': true,
+ 'browser-default': browserDefault
+ },
+ constants.SIZES.reduce((result, size) => {
+ return this.props[size]
+ ? Object.assign({}, result, { [size + this.props[size]]: true })
+ : result;
+ }, {})
+ );
return (
- <div className={cx(classes)}>
- <select
+ <div className={cx(classes)}>
+ <select
ref="__SELECT__"
value={this.state.value}
onChange={this._onChange.bind(this)} >
- {children}
- </select>
- <label>{label}</label>
- </div>
+ {children}
+ </select>
+ <label>{label}</label>
+ </div>
);
}
}
+Select.propTypes = {
+ onChange: PropTypes.func.isRequired,
+ children: PropTypes.node.isRequired,
+ s: PropTypes.number,
+ m: PropTypes.number,
+ l: PropTypes.number,
+ label: PropTypes.node,
+ defaultValue: PropTypes.string,
+ browserDefault: PropTypes.bool
+};
+
+Select.defaultProps = {
+ browserDefault: false
+};
+
+
export default Select;
--
2.7.2

There is no 'node_modules/materializecss/src/ng2-materializecss.js', but 'node_modules/materializecss/ng2-materializecss.js'.

And even though I do this, the test can not run. Because I got the following error:

PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
  ReferenceError: Can't find variable: require
  at /Users/scarlex/Projects/react-materialize/node_modules/materializecss/ng2-materializecss.js:4

My Node version is v5.6.0, and npm version is v3.7.5

Owner

isaiah commented Mar 6, 2016

I tried karma-jquery, but yet to find how to load materialize.js into global namespace.

Owner

isaiah commented Mar 6, 2016

Accidentally deleted the previous message:

The package name is wrong, it should be materialize-css instead of materializecss.

@isaiah

I have the same issue as fians/Waves#126

I try to upgrade phantomjs to 2.x, it works finally...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment