Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
test: add test for component fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 1, 2020
1 parent d8cc872 commit fe74a77
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/e2e/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ fixture`Fetch`
test('Shows fetched data on ssr-loaded page', async t => {
await t.navigateTo(`${url}/`)
await expectOnPage('name-Full Name')
await expectOnPage('component-Component data')
})

test('Shows fetched data on client-loaded page', async t => {
await t.navigateTo(`${url}/other/`)
await t.click(Selector('a'))
await expectPathnameToBe('/')
await expectOnPage('name-Full Name')
await expectOnPage('component-Component data')
})

test('Shows loading state', async t => {
Expand Down
31 changes: 31 additions & 0 deletions test/fixture/components/comp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div>
<div>component-{{ prop }}</div>
</div>
</template>

<script>
import { defineComponent, ref, computed, useFetch } from '../../..'
export function fetcher(result, time = 100) {
return new Promise(resolve => {
return setTimeout(() => {
resolve(result)
}, time)
})
}
export default defineComponent({
setup() {
const prop = ref('')
useFetch(async () => {
prop.value = await fetcher('Component data')
})
return {
prop,
}
}
})
</script>
6 changes: 5 additions & 1 deletion test/fixture/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
<div>{{ myFunction() }}</div>
<nuxt-link to="/other">link forward</nuxt-link>
<button @click="$fetch">Refetch</button>

<child-comp />
</div>
</template>

<script>
import { defineComponent, ref, computed, useFetch } from '../../..'
import ChildComp from '../components/comp.vue'
export function fetcher(result, time = 100) {
return new Promise(resolve => {
Expand All @@ -25,6 +26,9 @@ export function fetcher(result, time = 100) {
}
export default defineComponent({
components: {
ChildComp
},
setup() {
const name = ref('')
const email = ref('')
Expand Down

0 comments on commit fe74a77

Please sign in to comment.