Skip to content

Commit 4e97548

Browse files
committed
test: use mocks for commits e2e test
1 parent 80fb6b8 commit 4e97548

File tree

3 files changed

+592
-7
lines changed

3 files changed

+592
-7
lines changed

Diff for: examples/commits/app.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
/* global Vue */
2+
13
var apiURL = 'https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha='
24

35
/**
46
* Actual demo
57
*/
68

7-
var demo = new Vue({
9+
new Vue({
810

911
el: '#demo',
1012

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

3537
methods: {
3638
fetchData: function () {
37-
var xhr = new XMLHttpRequest()
3839
var self = this
39-
xhr.open('GET', apiURL + self.currentBranch)
40-
xhr.onload = function () {
41-
self.commits = JSON.parse(xhr.responseText)
42-
console.log(self.commits[0].html_url)
40+
if (navigator.userAgent.indexOf('PhantomJS') > -1) {
41+
// use mocks in e2e to avoid dependency on network / authentication
42+
setTimeout(function () {
43+
self.commits = window.MOCKS[self.currentBranch]
44+
}, 0)
45+
} else {
46+
var xhr = new XMLHttpRequest()
47+
xhr.open('GET', apiURL + self.currentBranch)
48+
xhr.onload = function () {
49+
self.commits = JSON.parse(xhr.responseText)
50+
console.log(self.commits[0].html_url)
51+
}
52+
xhr.send()
4353
}
44-
xhr.send()
4554
}
4655
}
4756
})

Diff for: examples/commits/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ <h1>Latest Vue.js Commits</h1>
4242
</li>
4343
</ul>
4444
</div>
45+
<script src="mock.js"></script>
4546
<script src="app.js"></script>
4647
</body>
4748
</html>

0 commit comments

Comments
 (0)