2024-02-05 17:41:44 +01:00

79 lines
1.4 KiB
JavaScript

import { shallowMount } from '@vue/test-utils'
import DateTime from '.'
const localVue = global.localVue
describe('DateTime', () => {
let mocks
let locale
let dateTime
beforeEach(() => {
mocks = {
$i18n: {
locale: () => locale,
},
}
})
const Wrapper = () => {
return shallowMount(DateTime, {
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().element.tagName).toBe('SPAN')
})
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')
})
})
})
})