Я пытаюсь протестировать метод vuejs, который получает переменную цвета из моего глобального файла. css. Я перепробовал много вещей (attachToDocument, identity-obj-proxy), но не нашел хороших решений.
dock. vue:
data () {
return {
nbPosition: this.nbPositions,
color: ''
}
},
methods: {
getColor () {
let color = getComputedStyle(document.documentElement).getPropertyValue('--color-neutral-grey')
if (this.anomaly === 1 || this.timer === -1) {
color = getComputedStyle(document.documentElement).getPropertyValue('--color-ano-red')
} else if (this.anomaly === 0) {
color = getComputedStyle(document.documentElement).getPropertyValue('--color-ano-orange')
}
this.color = color
}
}
dock.spe c. js:
import { shallowMount } from '@vue/test-utils'
import dock from '@/components/Storages/dock.vue'
describe('dock', () => {
// Testing Right border and no object and no anomaly
const wrapper = shallowMount(dock, {
mocks: {
$t: msg => msg
},
propsData: {
timer: -1,
index: 8,
anomaly: -1,
classNb: 0,
nbPositions: 10
}
})
test('Nothing - get border function: right border', () => {
expect(wrapper.html()).toContain('<div class="box border-right">')
})
test('Nothing - data: color and nbPosition', () => {
// eslint-disable-next-line no-console
console.log(wrapper.vm.color + ' and ' + wrapper.vm.nbPosition)
expect(wrapper.vm.color).toBe('#A1AABF')
expect(wrapper.vm.nbPosition).toBe(10)
})
test('Nothing - color class', () => {
expect(wrapper.classes()).toContain('index-number red')
})
}