Podcast
Questions and Answers
What is the purpose of the Test object?
What is the purpose of the Test object?
What is the message field used for?
What is the message field used for?
What is the purpose of the t.error() method?
What is the purpose of the t.error() method?
What is the purpose of the t.has() and t.notHas() methods?
What is the purpose of the t.has() and t.notHas() methods?
Signup and view all the answers
What is the purpose of the t.typeof() method?
What is the purpose of the t.typeof() method?
Signup and view all the answers
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.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
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.