javscript assert 1

javscript assert

//Code prints "Hello, ${username}!" and defaults to Jasmine if no username
//is provided

const hello = require('../hello.js');
const assert = require('assert'); //must require the assert

describe("hello", function(){
it("should return custom message when name is specified", function(){
   assert.strictEqual(hello("Jasmine"), "Hello, Jasmine!");
	});
});

assert.strictEqual(hello("Jasmine"), "Hello, Jasmine!"); 

Here is what the above code is Doing:
1. We’re requiring the hello.js file we created earlier.
2. We’re requiring the assert module.
3. We’re creating a test suite called hello.
4. We’re creating a test case called should return custom message when name is specified.
5. We’re using the assert module to check that the hello function returns the expected value when a name is provided.
6. We’re running the test case.

Similar Posts