Skip to content

Commit

Permalink
test: use mocks for commits e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 11, 2018
1 parent 80fb6b8 commit 4e97548
Show file tree
Hide file tree
Showing 3 changed files with 592 additions and 7 deletions.
23 changes: 16 additions & 7 deletions examples/commits/app.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',

Expand Down Expand Up @@ -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()
}
}
})
1 change: 1 addition & 0 deletions examples/commits/index.html
Expand Up @@ -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>

0 comments on commit 4e97548

Please sign in to comment.