Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Adding tests example to project #165

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"react",
"es2015"
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
node_modules
.DS_Store
.idea/
Empty file modified LICENSE
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -53,3 +53,9 @@ You can change the port number by setting the `$PORT` environment variable befor
```sh
PORT=3001 node server.js
```

## Testing

```sh
npm test
```
34 changes: 34 additions & 0 deletions __tests__/example-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
jest.unmock('../public/scripts/example.js');

var React = require('react');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('react-addons-test-utils');
var CommentBoxComponent = require('../public/scripts/example.js');

var CommentBox = CommentBoxComponent.CommentBox;

describe('TestCommentBoxComponent', () => {
var boxNode;
var commentBox;
beforeEach(() => {
commentBox = ReactTestUtils.renderIntoDocument(
<CommentBox url="/api/comments" pollInterval={2000} />
);
boxNode = ReactDOM.findDOMNode(commentBox);
});

it('should exists', function() {
expect(ReactTestUtils.isCompositeComponent(commentBox)).toBeTruthy();
});

it('class should equal commentBox', () => {
expect(boxNode.className).toEqual('commentBox');
});

it('initial state data should be empty', () => {
expect(commentBox.getInitialState()).toBeDefined();
const commentBoxData = commentBox.getInitialState().data;
expect(commentBoxData).toBeDefined();
expect(commentBoxData).toEqual([]);
})
})
Empty file modified app.json
100644 → 100755
Empty file.
10 changes: 10 additions & 0 deletions comments.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -23,5 +23,15 @@
"id": 1464988717637,
"author": "evil",
"text": "<a href=\"javascript:alert(1)\">alert(1)</a>"
},
{
"id": 1491409415686,
"author": "blah",
"text": "blah"
},
{
"id": 1491409439269,
"author": "testing",
"text": "test"
}
]
37 changes: 32 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -6,14 +6,41 @@
"description": "Code from the React tutorial.",
"main": "server.js",
"dependencies": {
"babel-jest": "^13.0.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"body-parser": "^1.4.3",
"express": "^4.4.5"
"express": "^4.4.5",
"jest-cli": "^13.0.0",
"jquery": "^3.2.1",
"react": "^15.1.0",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.1.0"
},
"devDependencies": {
"babel-preset-react": "^6.5.0",
"babelify": "^7.3.0",
"jest-cli": "^13.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"start": "node server.js"
},
"jest": {
"scriptPreprocessor": "./node_modules/babel-jest",
"testFileExtensions": [
"es6",
"js"
],
"moduleFileExtensions": [
"js",
"json",
"es6"
],
"unmockedModulePathPatterns": [
"./node_modules/react"
]
},
"repository": {
"type": "git",
"url": "https://github.com/reactjs/react-tutorial.git"
@@ -29,7 +56,7 @@
"url": "https://github.com/reactjs/react-tutorial/issues"
},
"homepage": "https://github.com/reactjs/react-tutorial",
"engines" : {
"node" : "0.12.x"
"engines": {
"node": "0.12.x"
}
}
Empty file modified public/css/base.css
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions public/index.html
100644 → 100755
Original file line number Diff line number Diff line change
@@ -13,10 +13,11 @@
</head>
<body>
<div id="content"></div>
<script type="text/babel" src="scripts/example.js"></script>
<!-- browserify -t [ babelify --presets [ react ] ] render.js -o bundle.js -->
<script src="scripts/bundle.js"></script>
<script type="text/babel">
// To get started with this tutorial running your own code, simply remove
// the script tag loading scripts/example.js and start writing code here.
// the script tag loading scripts/bundle.js and start writing code here.
</script>
</body>
</html>
152,298 changes: 152,298 additions & 0 deletions public/scripts/bundle.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions public/scripts/example.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var React = require('react');
var $ = require('jquery');

var Comment = React.createClass({
rawMarkup: function() {
@@ -141,7 +143,6 @@ var CommentForm = React.createClass({
}
});

ReactDOM.render(
<CommentBox url="/api/comments" pollInterval={2000} />,
document.getElementById('content')
);
module.exports = {
CommentBox: CommentBox
}
6 changes: 6 additions & 0 deletions public/scripts/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var CommentBox = require('./example.js').CommentBox;

ReactDOM.render(
<CommentBox url="/api/comments" pollInterval={2000} />,
document.getElementById('content')
);
19,599 changes: 19,599 additions & 0 deletions react.js

Large diffs are not rendered by default.

Empty file modified requirements.txt
100644 → 100755
Empty file.
Empty file modified server.go
100644 → 100755
Empty file.
Empty file modified server.js
100644 → 100755
Empty file.
Empty file modified server.php
100644 → 100755
Empty file.
Empty file modified server.pl
100644 → 100755
Empty file.
Empty file modified server.py
100644 → 100755
Empty file.
Empty file modified server.rb
100644 → 100755
Empty file.