3
これは私の最初の単体テストで、これまでのフォーラムでなぜそれを得るのか見つからないエラーメッセージが表示されます。ユニットテストでエラーが発生しましたvue.js karma:undefined isコンストラクタ()
これは私のユニットテストです:
import LoginPage from 'src/pages/Login'
describe('Login.vue',() => {
it('mounted is a fuction',() => {
expect(typeof LoginPage.mounted).toBe('function')
})
})
そして、これは、ログインページです:
<template>
<div class="">
<p v-if="$route.query.redirect">
You need to login first.
</p>
<form class="column is-one-third is-offset-one-third" @submit.prevent="login">
<div class="control">
<input type="email" placeholder="email" v-model="email" class="input">
</div>
<div class="control">
<input type="password" autocomplete="off" placeholder="password" v-model="pass" class="input">
</div>
<div class="control">
<button class="button is-primary" type="submit">Login</button>
<a class="button" href="/signup">Sign up</button>
</div>
<p v-if="error" class="help is-danger">{{ error }}</p>
</form>
</div>
</template>
<script>
export default {
props: ['state'],
data() {
return {
email: '',
pass: '',
error: ''
}
},
mounted() {
if (this.state.auth.currentUser) {
this.$router.replace(this.$route.query.redirect || '/')
}
},
methods:
{
....//
}
}
これは私が取得エラーメッセージです:あなたの助けのための
mounted is a fuction
Login.vue
undefined is not a constructor (evaluating 'expect((0, _typeof3.default)(_Login2.default.mounted)).toBe('function')')
webpack:///test/unit/specs/Component.spec.js:5:42 <- index.js:161:65
おかげ
[シンプルアサーションvuejs](https://vuejs.org/v2/guide/unit-testing。 html#Simple-Assertions)はそれほどとは言いません – smarber
@smarber「それ」は何でしょうか? –
私はtypeof: 'expect(typeof MyComponent.data).toBe( 'function')'でtoBeを使用することを意味しました。これはあなたが説明しているものではありません::解決策:expect(LoginPage.methods.mounted).toBe( 'function' )またはexpect(typeof LoginPage.methods.mounted).to.equal( 'function') ' – smarber