mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
by setting up localVue with all required plugins (such as styleguide and vuex) in a separate testSetup file we can avoid doing this individually in all component tests the testSetup is executed before each test suite, so each test file gets a fresh instance of localVue
79 lines
1.4 KiB
JavaScript
79 lines
1.4 KiB
JavaScript
import { shallowMount } from '@vue/test-utils'
|
|
import RelativeDateTime from './'
|
|
|
|
const localVue = global.localVue
|
|
|
|
describe('RelativeDateTime', () => {
|
|
let mocks
|
|
let locale
|
|
let dateTime
|
|
|
|
beforeEach(() => {
|
|
mocks = {
|
|
$i18n: {
|
|
locale: () => locale,
|
|
},
|
|
}
|
|
})
|
|
|
|
let Wrapper = () => {
|
|
return shallowMount(RelativeDateTime, {
|
|
mocks,
|
|
localVue,
|
|
propsData: {
|
|
dateTime,
|
|
},
|
|
})
|
|
}
|
|
|
|
describe('given a String as dateTime', () => {
|
|
beforeEach(() => {
|
|
dateTime = '08.03.2017'
|
|
})
|
|
|
|
it('translates', () => {
|
|
expect(Wrapper().text()).toContain('08/03/2017')
|
|
})
|
|
})
|
|
|
|
describe('given a Date object as dateTime', () => {
|
|
beforeEach(() => {
|
|
dateTime = new Date()
|
|
})
|
|
|
|
it('renders', () => {
|
|
expect(Wrapper().is('span')).toBe(true)
|
|
})
|
|
|
|
describe("locale == 'en'", () => {
|
|
beforeEach(() => {
|
|
locale = 'en'
|
|
})
|
|
|
|
it('translates', () => {
|
|
expect(Wrapper().text()).toContain('today at')
|
|
})
|
|
})
|
|
|
|
describe("locale == 'gibberish'", () => {
|
|
beforeEach(() => {
|
|
locale = 'gibberish'
|
|
})
|
|
|
|
it('translates', () => {
|
|
expect(Wrapper().text()).toContain('today at')
|
|
})
|
|
})
|
|
|
|
describe("locale == 'de'", () => {
|
|
beforeEach(() => {
|
|
locale = 'de'
|
|
})
|
|
|
|
it('translates', () => {
|
|
expect(Wrapper().text()).toContain('heute um')
|
|
})
|
|
})
|
|
})
|
|
})
|