Node.js मुखर मॉड्यूल
उदाहरण
यदि कोई अभिव्यक्ति 0 या गलत का मूल्यांकन करती है, तो एक त्रुटि फेंक दी जाती है और प्रोग्राम समाप्त हो जाता है:
var assert = require('assert');
assert(5 > 7);
परिभाषा और उपयोग
मुखर मॉड्यूल अभिव्यक्तियों का परीक्षण करने का एक तरीका प्रदान करता है। यदि व्यंजक का मूल्यांकन 0, या असत्य है, तो एक अभिकथन विफलता का कारण बन रहा है, और कार्यक्रम समाप्त हो गया है।
यह मॉड्यूल Node.js द्वारा आंतरिक रूप से उपयोग करने के लिए बनाया गया था।
वाक्य - विन्यास
अपने आवेदन में मुखर मॉड्यूल को शामिल करने के लिए वाक्य रचना:
var assert = require('assert');
मुखर तरीके
Method | Description |
---|---|
assert() | Checks if a value is true. Same as assert.ok() |
deepEqual() | Checks if two values are equal |
deepStrictEqual() | Checks if two values are equal, using the strict equal operator (===) |
doesNotThrow() | |
equal() | Checks if two values are equal, using the equal operator (==) |
fail() | Throws an Assertion Error |
ifError() | Throws a specified error if the specified error evaluates to true |
notDeepEqual() | Checks if two values are not equal |
notDeepStrictEqual() | Checks if two values are not equal, using the strict not equal operator (!==) |
notEqual() | Checks if two values are not equal, using the not equal operator (!=) |
notStrictEqual() | Checks if two values are not equal, using the strict not equal operator (!==) |
ok() | Checks if a value is true |
strictEqual() | Checks if two values are equal, using the strict equal operator (===) |
throws() |