Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

1.3 KiB

title
title
Test if an Object is an Instance of a Constructor

Test if an Object is an Instance of a Constructor


Problem Explanation

To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Objects'.

This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in /** 18 */ pass.


Hints

Hint 1

The challenge uses objects defined above the tests. Look closely at both, and determine whether the object is an instance of the type being compared against in the assertion.

Hint 2

Check the error messages to determine if your understanding of the object's instance was correct.

Hint 3

The lines in the test should be changed from assert.fail() to either assert.instanceOf() or assert.notInstanceOf().


Solutions

Solution 1 (Click to Show/Hide)
test('#instanceOf, #notInstanceOf', function() {
  /** 18 #instanceOf asserts that an object is an instance of a constructor **/
  // Use #instanceOf or #notInstanceOf where appropriate
  assert.notInstanceOf(myCar, Plane);
  assert.instanceOf(airlinePlane, Plane);
  assert.instanceOf(airlinePlane, Object, 'everything is an Object');
  assert.notInstanceOf(myCar.wheels, String);
});