I am creating some tests for my components.
But when I run coverage, I have this error:
import React from 'react'; IEE (statement not covered)
import classNames from "classnames"; EIII (branch not covered)
someone knows what happens?
that's my test and my component:
pagination-test.js
jest.unmock('../../../components/content/elements/pagination');
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Pagination from '../../../components/content/elements/pagination';
describe('Pagination', () => {
let setCurrentPage = jest.genMockFunction();
it('should render', () => {
let pagination = TestUtils.renderIntoDocument(
<Pagination setCurrentPage={setCurrentPage} page={1} totalPages={10} />
);
expect(pagination).toBeDefined();
});
it ('should have pagination element', () => {
let pagination = TestUtils.renderIntoDocument(
<Pagination setCurrentPage={setCurrentPage} page={1} total Pages={10} />
);
let renderedPagination = TestUtils.scryRenderedDOMComponentsWithTag(pagination, "li");
expect(renderedPagination.length).toEqual(12);
});
it ('should havent pagination element', () => {
let pagination = TestUtils.renderIntoDocument(
<Pagination setCurrentPage={setCurrentPage} page={0} totalPages={0} />
);
let renderedPagination = TestUtils.scryRenderedDOMComponentsWithTag(pagination, "ul");
expect(renderedPagination.length).toEqual(0);
});
});
pagination.js
import React from 'react';
import classNames from "classnames";
let PropTypes = React.PropTypes;
class Pagination extends React.Component {
constructor(props) {
super(props);
}
render() {
if (this.props.totalPages === 0) {
return React.DOM.div({'key': 'div-no-pagination'}, '');
}
let totalPages = [];
for (let x = 1; x <= this.props.totalPages; x++) {
totalPages.push(x);
}
let itinerator = 0;
let pages = totalPages.map(function(page) {
itinerator++;
let attr = {
href: '',
onClick: this.props.setCurrentPage.bind(this, page),
key: 'link_' + itinerator
}
let link = React.DOM.a(attr, page);
let active = false;
if (page == this.props.page) {
let active = true;
link = React.DOM.span({}, page);
}
return React.DOM.li({key: 'li_' + itinerator, className: classNames({'active': active})}, link);
}.bind(this));
let attrBack = {
href: '',
className: 'btn',
onClick: this.props.setCurrentPage.bind(this, (parseInt(this.props.page) - 1))
};
let attrNext = {
href: '',
className: 'btn',
onClick: this.props.setCurrentPage.bind(this, (parseInt(this.props.page) + 1))
};
let pagination = React.DOM.div({},
React.DOM.ul({},
React.DOM.li({}, React.DOM.a(attrBack, React.DOM.i({className: classNames({'fa fa-chevron-left': (this.props.page != 1)})}))),
pages,
React.DOM.li({}, React.DOM.a(attrNext, React.DOM.i({className: classNames({'fa fa-chevron-right': (this.props.page != this.props.totalPages)})})))
)
);
return (pagination);
}
}
Pagination.propTypes = {
setCurrentPage: PropTypes.func.isRequired,
page: PropTypes.number.isRequired,
totalPages: PropTypes.number.isRequired,
}
export default Pagination;
After exec jest --coverage, I have this
3 tests passed (3 total in 1 test suite, run time 0.995s)
---------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------------|----------|----------|----------|----------|----------------|
elements/ | 93.75 | 62.86 | 100 | 100 | |
pagination.js | 93.75 | 62.86 | 100 | 100 | |
----------------|----------|----------|----------|----------|----------------|
All files | 93.75 | 62.86 | 100 | 100 | |
----------------|----------|----------|----------|----------|----------------|
Aucun commentaire:
Enregistrer un commentaire