Bird
0
0

Identify the issue in this Angular test:

medium📝 Debug Q7 of 15
Angular - Testing
Identify the issue in this Angular test:
describe('Promise test', () => { it('checks resolved value', () => { const promise = Promise.resolve(10); expect(promise).toBe(10); }); });
AThe test uses an invalid Jasmine matcher
BThe test correctly compares the resolved value of the promise
CThe test is missing the describe block
DThe test compares a Promise object directly to a number without awaiting it
Step-by-Step Solution
Solution:
  1. Step 1: Understand Promise behavior

    A Promise is an object and must be awaited or resolved to get its value.
  2. Step 2: Analyze the test code

    The test compares the Promise object directly to a number, which is incorrect.
  3. Final Answer:

    The test compares a Promise object directly to a number without awaiting it -> Option D
  4. Quick Check:

    Always await promises before assertions [OK]
Quick Trick: Never compare Promise object directly to values [OK]
Common Mistakes:
  • Not awaiting asynchronous operations
  • Assuming Promise equals its resolved value
  • Ignoring async nature of tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes