javascript Nuxt测试Jest

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Nuxt测试Jest相关的知识,希望对你有一定的参考价值。

import { shallowMount, createLocalVue } from '@vue/test-utils'
import index from '../index'

const localVue = createLocalVue()

localVue.component('nuxt-link', {
  props: ['to'],
  template: '<a href="#"><slot>NuxtLink</slot></a>'
})

const factory = () => {
  return shallowMount(index, {
    stubs: ['nuxt-link'],
    localVue
  })
}

describe('index page', () => {
  test('mounts properly', () => {
    const wrapper = factory()
    expect(wrapper.isVueInstance()).toBeTruthy()
  })
})
import { shallowMount, createLocalVue } from '@vue/test-utils'
import index from '../index'

const localVue = createLocalVue()

localVue.component('nuxt-link', {
  props: ['to'],
  template: '<a href="#"><slot>NuxtLink</slot></a>'
})

const factory = () => {
  return shallowMount(index, {
    stubs: ['nuxt-link'],
    localVue
  })
}

describe('index page', () => {
  let cmp

  beforeEach(() => {
    cmp = factory()
  })

  afterEach(() => {
    cmp.destroy()
  })

  it('nextPages should be filled when starting game', () => {
    const startBtn = '.button-instructions'
    cmp.find(startBtn).trigger('click')
    expect(cmp.vm.nextPages).toHaveLength(3)
    expect(cmp.vm.nextPage).not.toEqual('/')
  })
})
import { shallowMount } from '@vue/test-utils'
import dateUtils from '../dateUtils'

const factory = () => {
  return shallowMount(dateUtils)
}

describe('dateUtils mixin', () => {
  let cmp

  beforeEach(() => {
    cmp = factory()
  })

  afterEach(() => {
    cmp.destroy()
  })

  it('dayWeek', () => {
    const dayWeek = cmp.vm.getDayWeek('2019-05-20 09:00')
    expect(dayWeek).toEqual('Lunes')
  })

  it('dayWeek empty', () => {
    const dayWeek = cmp.vm.getDayWeek('')
    expect(dayWeek).toEqual('')
  })
})

以上是关于javascript Nuxt测试Jest的主要内容,如果未能解决你的问题,请参考以下文章

使用 Nuxt 和 Jest 进行集成测试

使用 Jest 在 Nuxt 中测试组件时如何添加/模拟 Nuxt Auth 库

如何用 jest 测试 nuxt?

使用 Jest 测试 Nuxt + Vuex + Vuetify 的设置

如何在 Jest 测试中使用 nuxt 运行时配置变量

在 Nuxt、Vue、jest 和 Vuetify 中为项目编写单元测试