Skip to content

Commit

Permalink
commit first testing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Apr 22, 2015
1 parent 9d9ed9c commit 8a9bfc7
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
22 changes: 22 additions & 0 deletions __tests__/BootstrapTable-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
jest.dontMock('../src/BootstrapTable.js');
jest.dontMock('../src/TableHeaderColumn.js');
jest.dontMock('../src/TableBody.js');
jest.dontMock('../src/TableColumn.js');
jest.dontMock('../src/TableHeader.js');
jest.dontMock('../src/TableRow.js');
jest.dontMock('../src/pagination/PaginationList.js');
jest.dontMock('../src/pagination/PageButton.js');

describe('BootstrapTable', function() {
var testData = [
{id: 1, name: "name1", price: 100},
{id: 2, name: "name2", price: 120},
{id: 3, name: "name3", price: 130},
{id: 4, name: "name4", price: 140},
{id: 5, name: "name5", price: 110}
];

it('init', function() {

});
});
52 changes: 52 additions & 0 deletions __tests__/TableHeaderColumn-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
jest.dontMock('../src/BootstrapTable.js');
jest.dontMock('../src/TableHeaderColumn.js');
jest.dontMock('../src/TableBody.js');
jest.dontMock('../src/TableColumn.js');
jest.dontMock('../src/TableHeader.js');
jest.dontMock('../src/TableRow.js');
jest.dontMock('../src/pagination/PaginationList.js');
jest.dontMock('../src/pagination/PageButton.js');

describe('TableHeaderColumn Test', function() {

var React;
var TestUtils;
var ReactTestUtils;
var TableHeaderColumn;

beforeEach(function(){
React = require('react/addons');
TableHeaderColumn = require('../src/TableHeaderColumn.js');
TestUtils = React.addons.TestUtils;
ReactTestUtils = React.addons.ReactTestUtils;
});

it('A basic table header column test', function() {

var idHeaderColumn = TestUtils.renderIntoDocument(
<TableHeaderColumn dataField="id">Product ID</TableHeaderColumn>
);

expect(idHeaderColumn.props.dataField).toEqual("id");
expect(idHeaderColumn.props.children).toEqual("Product ID");
expect(idHeaderColumn.props.dataAlign).toEqual("left");
expect(idHeaderColumn.props.dataSort).toEqual(false);
expect(idHeaderColumn.props.dataFormat).toBe(undefined);


var reactThElm = TestUtils.findRenderedDOMComponentWithTag(idHeaderColumn, 'th');
expect(reactThElm).not.toBe(null);
var th = reactThElm.getDOMNode();
expect(th.className).toEqual("");
expect(th.childNodes.length).toEqual(1);

var reactDivElm = TestUtils.findRenderedDOMComponentWithTag(idHeaderColumn, 'div');
expect(reactDivElm).not.toBe(null);
var div = reactDivElm.getDOMNode();
expect(div.className).toEqual("th-inner table-header-column");
expect(div.textContent).toEqual("Product ID");

// ReactTestUtils.Simulate.click(reactDivElm);
// expect(th.getDOMNode()).toEqual(0);
});
});
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/AllenFang/react-bootstrap-table.git"
},
"scripts": {
"test": "Not yet implements."
"test": "jest"
},
"keywords": [
"react",
Expand Down Expand Up @@ -43,8 +43,6 @@
},
"jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react"
]
"unmockedModulePathPatterns": ["<rootDir>/node_modules/react"]
}
}
12 changes: 9 additions & 3 deletions preprocessor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// var ReactTools = require('react-tools');
var babel = require("babel");
module.exports = {
process: function(src) {
return babel.transform(src, { blacklist: ["react"] }).code;
process: function(src, filename) {
if (!babel.canCompile(filename)) {
return '';
}
// Ignore all files within node_modules
if (filename.indexOf('node_modules') === -1) {
return babel.transform(src, {filename: filename}).code;;
}
return src;
}
};

0 comments on commit 8a9bfc7

Please sign in to comment.