title: JavaScript: Test function
body: <p>I wrote the 'test' function for my 'counter', but it doesn't work! Can you help to understand where I am wrong?</p>
  
  <blockquote>
    <p>'test' must have a method called 'toEqual'!</p>
  </blockquote>
  
  <p>P.S.: 'counter' is good</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function test(data) {
   toEqual: function(e) {
         return (
               this.data.bind(this) == e ? console.log('good'):console.log('sucks!')
          );
   }
  }
  
  const counter = (state = 0, action) =&gt; {
      switch (action.type) {
          case 'INCREMENT':
              return state + 1;
          case 'DECREMENT':
              return state - 1;
          default:
              return state;
      }
  }
  
  test(
      counter(0, { type: 'INCREMENT' })
  ).toEqual(1);
  
  test(
      counter(1, { type: 'INCREMENT' })
  ).toEqual(2);
  
  test(
      counter(2, { type: 'DECREMENT' })
  ).toEqual(1);
  
  test(
      counter(2, { type: 'DECREMENT' })
  ).toEqual(0);
  
  test(
      counter(1, { type: 'SOMETHING_ELSE' })
  ).toEqual(1);
  
  test(
      counter(undefined, {})
  ).toEqual(0);</code></pre>
  </div>
  </div>
  </p>