>

CODEMASTERYLAB

IDE PLATFORM
CoursesCommunity BlogsKnowledge GraphQuizzesInterview Prep

Sign in to track progress & earn XP

Sign In Create Account
>
Code Mastery Lab

Code Mastery Lab

Sign In

Testing React and Redux

Question 1 / 1

0:00
Core
Medium

A developer writes the following reducer test:

it('RATE_COLOR success', () => {
  const state = {
    id: 0, title: 'Test Teal', color: '#90C3D4',
    timestamp: 'Sat Mar 12 2016', rating: 0
  }
  const action = { type: 'RATE_COLOR', id: 0, rating: 3 }
  const result = color(state, action)
  expect(result.rating).toBe(3)
})

The test passes. A code review reveals the reducer actually mutates state:

case 'RATE_COLOR':
  state.rating = action.rating
  return state

Why did the test pass despite the mutation, and what is the minimal change to make the test catch this bug?