Created
March 4, 2016 18:31
-
-
Save dshster/8a8d1130a326b23e9694 to your computer and use it in GitHub Desktop.
Angular e2e with http mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(application, dependencies) { | |
angular.module(application, dependencies); | |
})('application', []); | |
(function(application) { | |
angular.module(application) | |
.controller('SampleController', SampleController); | |
SampleController.$inject = ['$http']; | |
function SampleController($http) { | |
var Sample = this; | |
$http({ | |
method: 'GET', | |
url: '/foo' | |
}).success(function(result) { | |
Sample.message = result; | |
}).error(function(error) { | |
Sample.message = 'error: ' + error; | |
}); | |
} | |
})('application'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="/node_modules/angular/angular.min.js"></script> | |
<script src="/application.js"></script> | |
<title>Angular e2e testing</title> | |
</head> | |
<body ng-app="application"> | |
<div ng-controller="SampleController as Sample"> | |
<p class="message" ng-bind="Sample.message"></p> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "sample-test-components", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "http-server -o", | |
"test": "protractor protractor.conf.js" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"http-server": "0.9.0", | |
"protractor": "3.1.1", | |
"protractor-http-mock": "0.3.0" | |
}, | |
"dependencies": { | |
"angular": "1.5.0", | |
"protractor": "3.1.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.config = { | |
seleniumAddress: 'http://127.0.0.1:4444/wd/hub', | |
directConnect: true, | |
specs: ['./*.spec.js'], | |
mocks: { | |
dir: '', | |
default: [] | |
}, | |
capabilities: { | |
browserName: 'firefox' | |
}, | |
chromeOnly: true, | |
framework: 'jasmine', | |
jasmineNodeOpts: { | |
defaultTimeoutInterval: 30000 | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mock = require('protractor-http-mock'); | |
describe('starting test', function() { | |
var message; | |
beforeEach(function() { | |
browser.get('http://127.0.0.1:8080/'); | |
mock([{ | |
request: { | |
path: '/foo', | |
method: 'GET' | |
}, response: { | |
data: 'Angular e2e testing' | |
} | |
}]); | |
message = element(by.binding('Sample.message')); | |
}); | |
it('is present', function() { | |
expect(message.isPresent()).toBeTruthy(); | |
}); | |
it('is present', function() { | |
message.getText().then(function(text) { | |
expect(text).toEqual('Angular e2e testing'); | |
}); | |
}); | |
afterEach(function(){ | |
mock.teardown(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment