All files / molecule/pagination/src/customPropTypes isValidPage.js

100% Statements 12/12
100% Branches 8/8
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16    1x 5x 5x 5x 4x 3x 2x     1x        
import {getMessageErrorInRange, getMessageErrorNumber, getMessageErrorPositive} from './helpers.js'
 
const isValidPage = (props, propName, componentName) => {
  const page = props[propName]
  const {totalPages} = props
  if (page === undefined) return null
  if (typeof page !== 'number') return new Error(getMessageErrorNumber({propName, componentName}))
  if (page <= 0) return new Error(getMessageErrorPositive({propName, componentName}))
  if (page > totalPages) return new Error(getMessageErrorInRange({propName, componentName}))
 
  // assume all ok
  return null
}
 
export default isValidPage