我正在使用moment.js,并且在模拟格式功能时遇到了麻烦,收到了该错误:
TypeError:this。$ moment(...)。format不是函数
请问有人在正确的方向上指向我吗?
import { mount, createLocalVue, } from '@vue/test-utils'
import { expect } from 'chai'
import sinon from 'sinon'
import Vuex from 'vuex'
import authorisation from '../../src/components/settings/Authorisation.vue'
const localVue = createLocalVue()
localVue.use(Vuex)
const renewAuthStub = sinon.stub()
localVue.filter('translate', () => {})
describe ('settings authorisation', () => {
let wrapper
let store
let state
let getters
let actions
beforeEach(() => {
state = {
authorisation: {
authorised: '2018-03-18',
expiry: '03-04-2019',
canBeExtended: true
}
}
getters = {
fetchAuth: () => '',
isLoading: () => false,
authorisation: () => state.authorisation,
highlightDates: () => {},
disabledDates: () => {},
requestLoading: () => false
}
actions = {
fetchAuth: () => {}
}
store = new Vuex.Store({
state,
getters,
actions
})
wrapper = mount(authorisation, {
localVue,
store,
mocks: {
$moment: () => sinon.stub().resolves()
}
})
})
it('lets user know to reactivate when not authorised', () => {
答案 0 :(得分:0)
所以我意识到我正在使用udateLocale('en',English),因此我需要在测试中也使用它,因此需要添加以下内容:
import { mount, createLocalVue, } from '@vue/test-utils'
import { expect } from 'chai'
import sinon from 'sinon'
import Moment from 'moment'
import English from '../../src/i18n/moment/en'
import Vuex from 'vuex'
import Vue from 'vue'
import authorisation from '../../src/components/settings/Authorisation.vue'
const localVue = createLocalVue()
localVue.use(Vuex)
const renewAuthStub = sinon.stub()
localVue.filter('translate', () => {})
Vue.prototype.$moment = Moment
Moment.updateLocale('en', English)
describe ('settings authorisation', () => {