angular 从测试 ng-app 切换到开发 ng-app
angular switch from test ng-app to dev ng-app
所以这是我的问题我想在我 运行 测试或离线时模拟我的数据但是在我 can/want 时通过使用像 [=15] 这样的东西调用外部 API =] 和 npm run protractor-mock
.
我拼凑的解决方案是有 2 个 index.html
文件,其中一个添加了模拟 (index-mock.html
)。
所以我的问题是如何让设置 protractor-mock
加载 index-mock.html
注意:如代码中所述,GET('http://localhost:5000...
是错误的,但不是手头的问题。
我目前的文件
index.html:
<!DOCTYPE html>
<html lang="en" ng-app="PCA" class="no-js">
...
<script src="bower_components/angular/angular.js"></script>
...
</html>
索引-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
}
};
您可以访问量角器中的命令行参数。参见 How can I use command line arguments in Angularjs Protractor?。您应该能够使用它来区分两次运行,并将传递的 URL 更改为 browser.get
?
不是您的直接问题,但您可能想查看 Protractor 对模拟注入的支持。参见 the addMockModule
docs or http://eitanp461.blogspot.com/2014/01/advanced-protractor-features.html
您的应用程序不需要有两个实现,它可以与模拟或非模拟无关。
所以这是我的问题我想在我 运行 测试或离线时模拟我的数据但是在我 can/want 时通过使用像 [=15] 这样的东西调用外部 API =] 和 npm run protractor-mock
.
我拼凑的解决方案是有 2 个 index.html
文件,其中一个添加了模拟 (index-mock.html
)。
所以我的问题是如何让设置 protractor-mock
加载 index-mock.html
注意:如代码中所述,GET('http://localhost:5000...
是错误的,但不是手头的问题。
我目前的文件
index.html:
<!DOCTYPE html>
<html lang="en" ng-app="PCA" class="no-js">
...
<script src="bower_components/angular/angular.js"></script>
...
</html>
索引-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
}
};
您可以访问量角器中的命令行参数。参见 How can I use command line arguments in Angularjs Protractor?。您应该能够使用它来区分两次运行,并将传递的 URL 更改为 browser.get
?
不是您的直接问题,但您可能想查看 Protractor 对模拟注入的支持。参见 the addMockModule
docs or http://eitanp461.blogspot.com/2014/01/advanced-protractor-features.html
您的应用程序不需要有两个实现,它可以与模拟或非模拟无关。