在端到端测试期间修改场景.js 以模拟 AJAX 请求的最简单方法是什么?
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My Test AngularJS App</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular-resource.min.js"></script>
<script language="javascript" type="text/javascript">
angular.module('myApp', ['ngResource']);
function PlayerController($scope,$resource){
$scope.player = $resource('player.json').get();
}
</script>
</head>
<body ng-controller="PlayerController">
<p>Hello {{player.name}}</p>
</body>
</html>
Player 从服务器上名为 player.json 的文件中正确获取,并且以下测试通过。如何将不同的 json 传递给此测试并防止获取回服务器?
/*
How do I pass in
player.json -> {"name":"Chris"}
*/
describe('my app', function() {
beforeEach(function() {
browser().navigateTo('../../app/index.html');
});
it('should load player from player.json', function() {
expect(element('p:first').text()).
toMatch("Hello Chris");
pause();
});
});