jeudi 22 juin 2017

How to test a range of numbers with Jest?

I have:

const BOARD = {
  size: {
    columns: 5,
    rows: 5,
  },
}

and a Redux action creator that generates a position within the board's size:

const generateInitialPlayerPosition = (
  { 
    x = random(0, BOARD_SIZE.size.rows - 1), 
    y = random(0, BOARD_SIZE.size.columns - 1) 
  } = {}) => ({
  type: GENERATE_INITIAL_PLAYER_POSITION,
  payload: { x, y },
  }
)

I need to test that generateInitialPlayerPosition won't return any x or y greater than 4 in this case

Aucun commentaire:

Enregistrer un commentaire