The CreatorCon Call for Content is officially open! Get started here.

Jasmine Framework

gcs
Kilo Contributor

Hi,

I am new of Jasmine Framework , Can you please explain me how to use jasmine in service now and give me one example. 

Regards,

GCS 

8 REPLIES 8

Gajanan Birada1
Giga Expert

 

 

Hi,

 

https://developer.servicenow.com/blog.do?p=/tags/jasmine/

 

would be helpfule

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Please see a below example:

function(outputs, steps, stepResult, assertEqual) {
    // add test data in the array testEmails
    var one = 1,
        two = 2;

    var emailValid = new EmailValid();

    describe('my suite of script tests', function() { //This is a test suite in Jasmine
       
         it('should be one', function() { //This is a test
                        expect(one).toBe(1); //This will pass 
    	 });
    	
         it('should be one', function() { //This is a test
                        expect(two).toBe(1); //This will fail 
    	 });

         it('should not be one', function() { //This is a test
                        expect(two).not.toBe(1); //This will pass 
    	 });
    	


    });
})(outputs, steps, stepResult, assertEqual);

// uncomment the next line to execute this script as a jasmine test
jasmine.getEnv().execute();

Additional note, Jasmine is a behavior driver framework and can be used in combination with Javascript syntaxes for array traversing. I like this power to write parameterized cases. 

We can also use any of the existing Script Include in Jasmine.

Please find an example here https://community.servicenow.com/community?id=community_question&sys_id=5752e955dbeb5304feb1a851ca961941 

The example there uses both parameterization and Script Include.

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Here is a direct URL for the answer 
https://community.servicenow.com/community?id=community_question&sys_id=5752e955dbeb5304feb1a851ca961941&anchor=answer_191ba695dbef9304feb1a851ca96194e

arthurcheung
Kilo Expert

There are two example Jasmine tests out of the box:

  • Failing Jasmine Test
  • Jasmine Successful Test

Inside these are test steps that should show you how Jasmine is used if you search the sys_atf_test table. Basically there are three parts to each test:

  1. before (or beforeEach) - any setup you need to do for a test
  2. it - which is what you're testing
  3. after (or afterEach) - any clean up you need to do after a test

 

Jasmine is a common library used for JavaScript testing and isn't specific to ServiceNow. You're probably better off starting with their doco here.