Skip to content

gravadigital/protractor-xmlhttprequest-mock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protractor-xmlhttprequest-mock

Ajax calls mocking plugin for protractor, will work with angular 2 also.

A simple example of usage:

import {browser, $} from 'protractor';
import {MockService} from 'protractor-xmlhttprequest-mock';

describe('the backend', () => {
  it('should reply with code 418', async () => {
    await MockService.setup(browser);
    await MockService.addMock('mock1', {
      path: '/api/teapot',
      response: {status: 418, data: "I'm a teapot"},
    });

    expect($('div').getText()).toEqual("I'm a teapot");
  });
});

Using regex:

import {browser, $} from 'protractor';
import {MockService} from 'protractor-xmlhttprequest-mock';

describe('the backend', () => {
  it('should reply with code 418', () => {
    MockService.setup(browser);
    MockService.addMock('mock1', {
      path: /^(\/api)\/teapot\/[1-9a-z]/,
      response: {status: 418, data: "I'm a teapot"},
    });

    $('button').click();
    expect($('div').getText()).toEqual("I'm a teapot");
  });
});

Method support:

import {browser, $} from 'protractor';
import {MockService} from 'protractor-xmlhttprequest-mock';

describe('the backend', () => {
  it('should reply with code 418', () => {
    MockService.setup(browser);
    MockService.addMock('mock1', {
      path: '/api/teapot',
      mothod: 'get',
      response: {status: 418, data: "I'm a teapot"},
    });
    MockService.addMock('mock2', {
      path: '/api/teapot',
      mothod: 'post',
      response: {status: 401, data: "unauthorized"},
    });

    $('button').click();
    expect($('div').getText()).toEqual("I'm a teapot");
  });
});

Other examples can be found in tests folder.

About

Ajax calls mocking plugin for protractor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 73.3%
  • TypeScript 13.5%
  • HTML 13.1%
  • CSS 0.1%