Predict toContain Result
Predict Output Easy
Question
Will this test pass or fail?
Code
test('array contains', () => {
expect([1, 2, 3]).toContain(2);
});
Hint
The array [1, 2, 3] does contain 2.
Explanation
The test passes. toContain checks whether the given value is present in the array (or substring in a string). Since 2 is an element of [1, 2, 3], the assertion passes.
Related Resources
Related Lessons
- Assertions
Using assertions to verify behavior.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.