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的主要内容,如果未能解决你的问题,请参考以下文章