-
Notifications
You must be signed in to change notification settings - Fork 74
Karma + Jasmine test runner #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"stage": 0, | ||
"plugins": [ | ||
"react-transform" | ||
], | ||
"extra": { | ||
"react-transform": [{ | ||
"target": "react-transform-webpack-hmr", | ||
"imports": ["react"], | ||
// this is important for Webpack HMR: | ||
"locals": ["module"] | ||
}, | ||
{ | ||
"target": "react-transform-catch-errors", | ||
// the second import is the React component to render error | ||
// (it can be a local path too, like "./src/ErrorReporter") | ||
"imports": ["react", "redbox-react"] | ||
}] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// See this for some tips with Meteor: https://medium.com/all-about-meteorjs/unit-test-react-components-in-meteor-a19d96684d7d | ||
|
||
// If you import ../App you'll have to stub out Meteor, this is | ||
// why it's important to use controller-views that just setup | ||
// data and then the children can be very easily tested with | ||
// just props and state. We'll use a local component for an example | ||
|
||
import React from 'react/addons'; | ||
//import App from '../App'; | ||
//import $ from 'jquery'; // you could use jq to make life easier | ||
const TestUtils = React.addons.TestUtils; | ||
const Simulate = TestUtils.Simulate; | ||
|
||
// these should go into a spec helper module | ||
|
||
function renderComponent(comp, props) { | ||
return TestUtils.renderIntoDocument( | ||
React.createElement(comp, props) | ||
); | ||
} | ||
|
||
function simulateClickOn(selector) { | ||
var button = this.$el.find(selector)[0]; | ||
React.addons.TestUtils.Simulate.click(button); | ||
} | ||
|
||
|
||
const Post = React.createClass({ | ||
getDefaultProps() { | ||
return {title: "Default Post Name"}; | ||
}, | ||
getInitialState() { | ||
return { isVisible: true }; | ||
}, | ||
handleHide() { | ||
this.setState({isVisible: false}); | ||
}, | ||
render() { | ||
let visibleClass = (this.state.isVisible) ? 'block' : 'hidden'; | ||
return ( | ||
<div className='Post' style={{display: visibleClass }}> | ||
<h1>{this.props.title}</h1> | ||
<article> | ||
How now brown cow | ||
</article> | ||
<button onClick={this.handleHide}>Hide</button> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
|
||
describe('Sample post component', () => { | ||
it('renders default post name without props', () => { | ||
let comp = renderComponent(Post, {}); | ||
expect(comp.props.title).toEqual('Default Post Name'); | ||
}); | ||
|
||
it('renders correct post name with a name prop', () => { | ||
let comp = renderComponent(Post, {title: "Webpack is awesome!"}); | ||
expect(comp.props.title).toEqual("Webpack is awesome!"); | ||
}); | ||
|
||
it("should have a default state of visible", () => { | ||
let comp = renderComponent(Post, {}); | ||
expect(comp.state.isVisible).toEqual(true); | ||
}); | ||
|
||
it("should hide when hide button is clicked", () => { | ||
let comp = renderComponent(Post, {}); | ||
comp.handleHide(); | ||
expect(comp.state.isVisible).toEqual(false); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var path = require('path'); | ||
var webpackConfig = require('./webpack/webpack.config.client.js'); | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
//singleRun: true, | ||
reporters: [ 'dots' ], | ||
browsers: [ 'Chrome' ], | ||
files: [ './test/karma.bundle.js' ], | ||
frameworks: [ 'jasmine' ], | ||
plugins: [ | ||
'karma-chrome-launcher', | ||
//'karma-firefox-launcher', | ||
'karma-jasmine', | ||
//'karma-mocha', | ||
'karma-sourcemap-loader', | ||
'karma-webpack', | ||
], | ||
// run the bundle through the webpack and sourcemap plugins | ||
preprocessors: { | ||
'./test/karma.bundle.js': [ 'webpack', 'sourcemap' ] | ||
}, | ||
// use our own webpack config to mirror test setup | ||
webpack: { | ||
entry: [ | ||
'./lib/core-js-no-number', | ||
'regenerator/runtime', | ||
], | ||
devtool: 'eval-source-map', | ||
resolve: webpackConfig.resolve, | ||
module: { loaders: webpackConfig.module.loaders }, | ||
}, | ||
webpackMiddleware: { | ||
noInfo: true, | ||
} | ||
}); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// require all foo_spec.js, bar_spec.jsx files in the app directory | ||
var context = require.context('../app', true, /.+_spec\.jsx?$/); | ||
context.keys().forEach(context); | ||
module.exports = context; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, any way we could make the test have something to do with what's actually in the App stub instead of this?