title: What is the difference between 'toBe' and 'toEqual' in Jest?
body: <p>Jest documentation reads:</p>
  
  <blockquote>
    <p>toBe just checks that a value is what you expect. It uses === to check strict equality.  </p>
  </blockquote>
  
  <p>And for <code>toEqual</code>:</p>
  
  <blockquote>
    <p>Use .toEqual when you want to check that two objects have the same value. This matcher recursively checks the equality of all fields, rather than checking for object identity—this is also known as "deep equal". For example, toEqual and toBe behave differently in this test suite, so all the tests pass.</p>
  </blockquote>
  
  <pre class="lang-js prettyprint-override"><code>const x = { a: { b: 3 } };
  const y = { a: { b: 3 } };
  
  expect(x).toEqual(y);
  expect(x).toBe(y);
  </code></pre>
  
  <p>In this case, <code>toEqual</code> passes but <code>toBe</code> fails. I understand that <code>toEqual</code> passes because it does a <em>deep equal</em> check. Why is <code>toBe</code> failing in this case?</p>
  
  <p>Also, are there best practices for using <code>toBe</code> and <code>toEqual</code> (not just in Jest but in other testing frameworks, too)?</p>