我只是在开玩笑地学习 Nuxt。我的test.vue。刚刚从https://nuxtjs.org/docs/2.x/features/data-fetching复制
<template>
<div>
<h1 class="page-title">Mountains</h1>
<p v-if="$fetchState.pending">Fetching mountains...</p>
<p v-else-if="$fetchState.error">An error occurred :(</p>
<div v-else>
<h1>Nuxt Mountains</h1>
<ul>
<li v-for="mountain of mountains">{{ mountain.title }}</li>
</ul>
<button @click="$fetch">Refresh</button>
</div>
</div>
</template>
<script>
export default {
data () {
return {
mountains: [],
}
},
async fetch () {
this.products = await fetch(
'https://api.nuxtjs.dev/mountains'
).then(res => res.json())
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的 test.spec.js
import { mount } from '@vue/test-utils'
import Test from '@/components/test.vue'
describe('Test', () => {
test('is a Vue …Run Code Online (Sandbox Code Playgroud)