Permalink
Browse files

test: use mocks for commits e2e test

  • Loading branch information...
yyx990803 committed Dec 11, 2018
1 parent 80fb6b8 commit 4e975485a4d90fef62bf73a32a2b72e249919130
Showing with 592 additions and 7 deletions.
  1. +16 −7 examples/commits/app.js
  2. +1 −0 examples/commits/index.html
  3. +575 −0 examples/commits/mock.js
@@ -1,10 +1,12 @@
/* global Vue */

var apiURL = 'https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha='

/**
* Actual demo
*/

var demo = new Vue({
new Vue({

el: '#demo',

@@ -34,14 +36,21 @@ var demo = new Vue({

methods: {
fetchData: function () {
var xhr = new XMLHttpRequest()
var self = this
xhr.open('GET', apiURL + self.currentBranch)
xhr.onload = function () {
self.commits = JSON.parse(xhr.responseText)
console.log(self.commits[0].html_url)
if (navigator.userAgent.indexOf('PhantomJS') > -1) {
// use mocks in e2e to avoid dependency on network / authentication
setTimeout(function () {
self.commits = window.MOCKS[self.currentBranch]
}, 0)
} else {
var xhr = new XMLHttpRequest()
xhr.open('GET', apiURL + self.currentBranch)
xhr.onload = function () {
self.commits = JSON.parse(xhr.responseText)
console.log(self.commits[0].html_url)
}
xhr.send()
}
xhr.send()
}
}
})
@@ -42,6 +42,7 @@ <h1>Latest Vue.js Commits</h1>
</li>
</ul>
</div>
<script src="mock.js"></script>
<script src="app.js"></script>
</body>
</html>
Oops, something went wrong.

0 comments on commit 4e97548

Please sign in to comment.