Skip to main content
InterviewHubPRO
Section Overview
Q9

Question 9 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

18%
Software Testing & QA (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

Assertions Deep Dive: Deep Equality vs. Strict Equality and Async Assertions.

junior LevelCode ExampleAsync & Promises

In Simple Words:

  • Strict Equality (toBe / ===): Compares memory references for objects and values for primitives. Fails if two distinct objects have identical keys and values!
  • Deep Equality (toEqual): Recursively inspects all properties, keys, and values of objects and arrays.
  • Async Assertions: Always await asynchronous expectations:
    typescript
    // ❌ BROKEN: Test completes before promise rejects!
    expect(fetchUser(-1)).rejects.toThrow();
    
    // ✅ CORRECT: Awaited rejection assertion
    await expect(fetchUser(-1)).rejects.toThrow('User not found');