Fakultas Ilmu Komputer UI

Commit fbfd18fe authored by M. Reza Qorib's avatar M. Reza Qorib
Browse files

#140382397 #3 akhirnya test nya bisa jalan :')

parent edebb756
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-addons-test-utils' // ES6
import expect from 'expect';
import Root from '../root';
describe('root', function () {
it('renders without problems', function () {
let root = ReactTestUtils.renderIntoDocument(<Root/>);
expect(root).toExist();
});
it('changes without problems', function () {
let root = ReactTestUtils.renderIntoDocument(<Root/>);
const inputNode = ReactDOM.findDOMNode(root.refs.input);
const newValue = 'some text';
inputNode.value = newValue;
ReactTestUtils.Simulate.change(inputNode);
const nameNode = ReactDOM.findDOMNode(root.refs.name);
expect(nameNode.textContent).toEqual(newValue);
});
});
\ No newline at end of file
var React = require('react');
var TestUtils = require('../../node_modules/react-test-utils/ReactTestUtils'); //I like using the Test Utils, but you can just use the DOM API instead.
var expect = require('expect');
//var Root = require('component'); //my root-test lives in components/__tests__/, so this is how I require in my components.
it("renders an h1", function () {
var component = TestUtils.renderIntoDocument(
<MyComponent />
);
var h1 = TestUtils.findRenderedDOMComponentWithTag(
component, 'h1'
);
expect(h1.getDOMNode().textContent)
.toEqual("A title");
});
//replace “//will insert additional tests here later” with the following:
// describe("appending strings", function() {
// it("should be able to append 2 strings", function() {
// expect(myfunc.append).toBeDefined();
// });
// it("should append 2 strings", function() {
// expect(myfunc.append('hello ','world')).toEqual('hello world');
// });
// });
\ No newline at end of file
/**
* Created by M. Reza Qorib on 3/11/2017.
*/
import React from 'react';
class Root extends React.Component {
constructor(props) {
super(props);
this.state = {
name: ''
};
this.handleChange = (e) => {
var newName = e.target.value;
this.setState({
name: newName
});
}
}
render() {
return (
<div>
<h1>Hello World!!</h1>
<p>
Please input your name here:
<input ref="input"
onChange={this.handleChange}
value={this.state.name}
/>
</p>
<p>Hello, <span ref="name">{this.state.name}</span> </p>
</div>
);
}
}
export default Root;
\ No newline at end of file
......@@ -22,7 +22,7 @@
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>2/2</span>
<span class='fraction'>0/0</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
......@@ -37,7 +37,7 @@
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>2/2</span>
<span class='fraction'>0/0</span>
</div>
</div>
</div>
......@@ -58,26 +58,13 @@
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="kape/"><a href="kape/index.html">kape/</a></td>
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="2" class="abs high">2/2</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="0" class="abs high">0/0</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="0" class="abs high">0/0</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="2" class="abs high">2/2</td>
</tr>
</tbody>
<tbody></tbody>
</table>
</div><div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Mar 11 2017 06:20:02 GMT+0700 (SE Asia Standard Time)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Mar 11 2017 07:29:56 GMT+0700 (SE Asia Standard Time)
</div>
</div>
<script src="prettify.js"></script>
......
......@@ -77,7 +77,7 @@
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Mar 11 2017 06:20:02 GMT+0700 (SE Asia Standard Time)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Mar 11 2017 07:08:55 GMT+0700 (SE Asia Standard Time)
</div>
</div>
<script src="../prettify.js"></script>
......
......@@ -45,14 +45,14 @@
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2</td><td class="line-coverage quiet"><span class="cline-any cline-yes"></span>
<span class="cline-any cline-yes"></span></td><td class="text"><pre class="prettyprint lang-js">var context = require.context('./assets/js', true, /-test\.js$/); //make sure you have your directory and regex test set correctly!
<span class="cline-any cline-yes"></span></td><td class="text"><pre class="prettyprint lang-js">var context = require.context('./assets/js', true, /-test\.js/); //make sure you have your directory and regex test set correctly!
context.keys().forEach(context);</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Mar 11 2017 06:20:02 GMT+0700 (SE Asia Standard Time)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Mar 11 2017 07:08:55 GMT+0700 (SE Asia Standard Time)
</div>
</div>
<script src="../prettify.js"></script>
......
var webpack = require('webpack');
var webpackConfig = require('./webpack.config');
webpackConfig.devtool = 'inline-source-map';
module.exports = function (config) {
config.set({
......@@ -15,18 +16,7 @@ module.exports = function (config) {
'tests.webpack.js': [ 'webpack', 'sourcemap' ] //preprocess with webpack and our sourcemap loader
},
reporters: [ 'dots', 'coverage' ], //report results in this format
webpack: { //kind of a copy of your webpack config
devtool: 'inline-source-map', //just do inline source maps instead of the default
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader' }
],
postLoaders: [ { //delays coverage til after tests are run, fixing transpiled source coverage error
test: /\.js$/,
exclude: /(test|node_modules|bower_components)\//,
loader: 'istanbul-instrumenter' } ]
}
},
webpack: webpackConfig,
webpackServer: {
noInfo: true //please don't spam the console when running in karma!
},
......
var context = require.context('./assets/js', true, /-test\.js$/); //make sure you have your directory and regex test set correctly!
var context = require.context('./assets/js', true, /-test\.js/); //make sure you have your directory and regex test set correctly!
context.keys().forEach(context);
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment