So here is my problem I want to mock my data when I run tests or am offline but call the extarnal API when I can/want by using somthing like npm run protractor
and npm run protractor-mock
.
the solution I have cobbled together is having 2 index.html
files one with the addition of mock (index-mock.html
).
So my question is how can I tell setup protractor-mock
to load index-mock.html
Note: as stated in the code GET('http://localhost:5000...
is bad but not the issue at hand.
my files so far
index.html:
<!DOCTYPE html>
<html lang="en" ng-app="PCA" class="no-js">
...
<script src="bower_components/angular/angular.js"></script>
...
</html>
index-mock.html:
<!DOCTYPE html>
<html lang="en" ng-app="PCA" class="no-js">
...
<script src="bower_components/angular/angular.js"></script>
...
</html>
app.js:
'use strict';
angular.module('PCA', [
'ngRoute',
'chart.js',
'ngDialog',
'ngCsv'
]).config(function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'views/chartContainer.html',
controller: 'chartContainerCtrl'
}).otherwise({redirectTo: '/'});
}).constant('config', {
'apiUrl': 'http://localhost:5000'
});
//2nd app ->
angular.module('PCAMOCK', ['PCA', 'ngMockE2E'])
.run(function($httpBackend) {
$httpBackend.whenGET('http://localhost:5000/').respond({ //yes 'localhost:5000' this is bad but not the issues at hand
"defaults": {
"invURL": "http://www.invURL.com",
"accountURL": "http://www.accountURL.com"
}});
$httpBackend.whenGET('http://localhost:5000/accounts').respond(200, {ciao:'mamma'}, {'Content-Type':'application/json'});
$httpBackend.whenGET(/^/).passThrough();
//...
});
package.json:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'tests/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8000/app/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};