Skip to content

Commit

Permalink
Merge pull request #39 from valentinz/protractor-http-mock
Browse files Browse the repository at this point in the history
Integrated protractor-http-mock.
  • Loading branch information
valentinz committed Nov 24, 2015
2 parents b41b15d + 8584bf2 commit f3d416a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 75 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"node-sass": "^3.3.3",
"portfinder": "^0.4.0",
"protractor": "git+https://github.com/jGleitz/protractor.git#browserstack",
"protractor-http-mock": "^0.1.18",
"q": "^1.4.1",
"sass-lint": "^1.3.2",
"serve-static": "^1.10.0",
Expand Down
55 changes: 0 additions & 55 deletions test/behaviour/apimocker.js

This file was deleted.

22 changes: 5 additions & 17 deletions test/behaviour/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require('./asserters')();

var server = require('./apimocker');
var mock = require('./http-mock');

describe('Home', function() {
this.timeout(1 * 60 * 1000);
Expand All @@ -23,25 +23,13 @@ describe('List', function() {
var locationlist = by.repeater('location in ctrl.locations');

it('should have two entries: "Sandsäcke füllen" and "Transport"', function() {
mock(['locations']);

browser.getPart('list');

expect(element.all(locationlist).count()).to.eventually.equal(2);
expect(element.all(locationlist).count()).to.eventually.equal(3);
expect(element(locationlist.column('location.name').row(0)).getInnerHtml()).to.eventually.contain('Sandsäcke füllen');
expect(element(locationlist.column('location.name').row(1)).getInnerHtml()).to.eventually.contain('Transport');
});

// Example for mocking
it('should load another entry', function() {
server.mockAPI('locations', [{
id: 1,
name: 'Mocked Location',
latitude: 49.1232,
longitude: 8,
location: 'Schlossplatz'
}]);

browser.navigate().refresh();

expect(element(locationlist.column('location.name').row(0)).getInnerHtml()).to.eventually.contain('Mocked Location');
expect(element(locationlist.column('location.name').row(2)).getInnerHtml()).to.eventually.contain('Test 3');
});
});
6 changes: 6 additions & 0 deletions test/behaviour/http-mock.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.config = {
mocks: {
dir: 'mocks',
default: ['default']
}
};
8 changes: 8 additions & 0 deletions test/behaviour/http-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

var mock = require('protractor-http-mock');
mock.config = {
rootDirectory: __dirname, // default value: process.cwd()
protractorConfig: 'http-mock.conf.js'
};

module.exports = mock;
11 changes: 11 additions & 0 deletions test/behaviour/mocks/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
request: {
path: '/default',
method: 'GET'
},
response: {
data: {
name: "i'm always loaded"
}
}
};
33 changes: 33 additions & 0 deletions test/behaviour/mocks/locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
request: {
path: '/locations',
method: 'GET'
},
response: {
data: [{
id: 1,
name: 'Sandsäcke füllen',
latitude: 49.1232,
longitude: 8,
location: 'Schlossplatz'
}, {
id: 2,
name: 'Transport',
latitude: 48.1232,
longitude: 8,
location: 'Rheinbad',
options: {
title: 'Transport im Rheinbad'
}
}, {
id: 2,
name: 'Test 3',
latitude: 48.1232,
longitude: 8,
location: 'Rheinbad',
options: {
title: 'Transport im Rheinbad'
}
}]
}
};
4 changes: 1 addition & 3 deletions test/behaviour/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Sets up the test environment
*/

var mocker = require('./apimocker');
var portfinder = require('portfinder');
var Server = require('../../tasks/server');

Expand Down Expand Up @@ -30,8 +29,7 @@ before('Expose globals', function() {
};
});

before('Set up the JSON server and mocker', function() {
before('Set up the HTTP server', function() {
var server = new Server();
server.use(mocker.middleware);
server.listen(port);
});

0 comments on commit f3d416a

Please sign in to comment.