Prev Next

Testing / Jasmine Interview Questions

Could not find what you were looking for? send us the question and we would be happy to answer your question.

1. What is Jasmine?

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.

Karma is a tool of running tests on browsers it lets us spawn browsers and run jasmine tests inside of them.

function message() {
  return 'Hello world!';
}

We would write a jasmine test spec like so:

describe('Hello world', () => { 
  it('says hello', () => { 
    expect(message()) 
        .toEqual('Hello world!'); 
  });
});

2. Is Jasmine a BDD?

Jasmine is a JavaScript-based Behavior Driven Development (BDD) testing framework. It is not dependent on any browsers, the DOM, or JavaScript frameworks.

3. How can we disable tests in Jasmine?

We can disable tests by using xit instead of 'it', xdescribe instead of 'describe' as shown below:

xdescribe('Hello', () => { (1)
  xit('says Hello', () => { (1)
    expect(Hello())
        .toEqual('Hello!');
  });
});
4. What is Karma?

Karma is a tool of running tests on browsers it lets us spawn browsers and run jasmine tests inside of them.

5. What are the built-in matchers in Jasmine?
expect(array).toContain(member);
expect(fn).toThrow(string);
expect(fn).toThrowError(string);
expect(instance).toBe(instance);
expect(mixed).toBeDefined();
expect(mixed).toBeFalsy();
expect(mixed).toBeNull();
expect(mixed).toBeTruthy();
expect(mixed).toBeUndefined();
expect(mixed).toEqual(mixed);
expect(mixed).toMatch(pattern);
expect(number).toBeCloseTo(number, decimalPlaces);
expect(number).toBeGreaterThan(number);
expect(number).toBeLessThan(number);
expect(number).toBeNaN();
expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledTimes(number);
expect(spy).toHaveBeenCalledWith(...arguments);
6. Explain Setup and teardown in Jasmine.

beforeAll: This function is called once, before all the specs in describe test suite are run.

afterAll: This function is called once after all the specs in a test suite are finished.

beforeEach: This function is called before each test specification, it function, has been run.

afterEach: This function is called after each test specification has been run.

describe('Hello world', () => {

  let expected = "";

  beforeEach(() => {
    expected = "Hello World";
  });

  afterEach(() => {
    expected = "";
  });

  it('says hello', () => {
    expect(message())
        .toEqual(expected);
  });
});

7. What is Protractor?

Protractor is an end-to-end test framework for Angular. It runs your tests inside a real browser, interacting with it as real person would. Unlike unit tests, where we test individual functions, here we test the entire logic. Protractor is able to fill in forms, click buttons and confirm that the expected data and styling is displayed in the HTML document.

«
»
Cypress Interview Questions

Comments & Discussions