test(e2e): add e2e test for commits example (#526)

* test(e2e): add e2e test for commits example

* test(e2e): add waitForResponse to enhance the test

* test(e2e): use mocks for commits test
This commit is contained in:
CodinCat
2019-12-11 23:51:15 +09:00
committed by Evan You
parent 2a994094de
commit f48a4f71a7
4 changed files with 639 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
<script src="../../dist/vue.global.js"></script>
<script src="../mocks/commits.js"></script>
<div id="demo">
<h1>Latest Vue.js Commits</h1>
@@ -37,10 +38,17 @@ const App = {
const currentBranch = ref('master')
const commits = ref(null)
watch(() => {
fetch(`${API_URL}${currentBranch.value}`)
.then(res => res.json())
.then(data => { commits.value = data })
watch([currentBranch, commits], () => {
if (window.location.hash === '#test') {
// use mocks in e2e to avoid dependency on network / authentication
setTimeout(() => {
commits.value = window.MOCKS[currentBranch.value]
}, 0)
} else {
fetch(`${API_URL}${currentBranch.value}`)
.then(res => res.json())
.then(data => { commits.value = data })
}
})
return {