Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/expect@%3C21/umd/expect.min.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const counter = (state = 0, action) => {
  
  switch (action.type) {
    case 'INCREMENT':
      return state + 1;
    case 'DECREMENT':
      return state - 1;
    default:
      return state;
  }
}
expect(
  counter(0, { type: 'INCREMENT' })
).toEqual(1);
expect(
  counter(1, { type: 'INCREMENT' })
).toEqual(2);
expect(
  counter(2, { type: 'DECREMENT' })
).toEqual(1);
expect(
  counter(1, { type: 'DECREMENT' })
).toEqual(0);
expect(
  counter(1, { type: 'SOMETHING_ELSE' })
).toEqual(1);
expect(
  counter(undefined, {})
).toEqual(0);
  
console.log('Tests passed!');
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers