Node.js Test Object Methods Quiz

Start Quiz

Study Flashcards

5 Questions

What is the purpose of the Test object?

To provide a collection of assertion methods

What is the message field used for?

To provide the name of the test

What is the purpose of the t.error() method?

To handle any unexpected errors

What is the purpose of the t.has() and t.notHas() methods?

To check if an object contains certain fields or not

What is the purpose of the t.typeof() method?

To check the type of an object

Study Notes

  • The Test object has a collection of assertion methods.
  • All assertion methods take optional message and extra arguments.
  • The message is the name of the test. The extra argument can contain any arbitrary data about the test, but the following fields are "special".
  • If an error is encountered unexpectedly, it's often better to simply throw it. The Test object will handle this as a failure.
  • t.error(obj, message, extra)
  • t.emits(eventEmitter, event, message, extra)
  • t.rejects(promise | fn, [expectedError], message, extra)
  • t.resolves(promise | fn, message, extra)
  • t.resolveMatch(promise | fn, wanted, message, extra)
  • t.resolveMatchSnapshot(promise | fn, message, extra)
  • t.throws(fn, [expectedError], message, extra)
  • If the function has a name, and the message is not provided, then the function name will be used as the message.
  • If the function is not provided, then this will be treated as a todo test.
  • The t.doesNotThrow() and t.expectUncaughtException() methods allow you to verify that a function does not throw an error, and that it will not do so in the future.
  • The t.equal(), t.notEqual(), and t.same() methods allow you to verify that two objects are equal, not equal, or deeply equivalent to each other, respectively.
  • The t.has() and t.notHas() methods allow you to verify that a field is present in an object, or not present, respectively.
  • The t.strictSame(), t.strictNotSame(), and t.hasStrict() methods allow you to verify that fields in an object are strictly equivalent, not equivalent, or have the same value, respectively.
  • t.has() and t.notHas() are used to check if an object contains certain fields or not.
  • t.hasProp() and t.notHasProp() are used to check if an object contains a certain property or not.
  • t.hasOwnProp() and t.notHasOwnProp() are used to check if an object contains a certain property or not.
  • t.type() is used to check the type of an object.
  • t.match() and t.notMatch() are used to check if an object matches a certain pattern or not.
  • t.typeof() is used to check the type of an object.

Test your knowledge of the assertion methods of the Test object in Node.js. This quiz covers various assertion methods like t.error(), t.emits(), t.rejects(), t.resolves(), t.equal(), and more.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser