xiCO2k / laravel-vue-i18n

Allows to connect your `Laravel` Framework translation files with `Vue`.
MIT License
584 stars 49 forks source link

Inject your package on Unit Test #176

Open zacktagnan opened 2 months ago

zacktagnan commented 2 months ago

Hi:

Before including your translations package on the project, the Unit test I implemented was OK. But once I set the translate helpers on the Vue component called by the test, this test fails.

[ .tests/Unit/Habits/Info.test.js ]

import { describe, it, expect, beforeEach } from "vitest";
import { mount } from "@vue/test-utils";
import HabitInfo from '@/components/Habit/Info.vue'

describe('HabitInfo.vue', () => {
    let wrapper = null

    beforeEach(() => {
        wrapper = mount(HabitInfo, {
            props: {
                name: 'Beber agua',
                executions_count: 1,
                times_per_day: 3,
            }
        })
    })

    it('displays the habit name', () => {
        expect(wrapper.find('#name').text()).toBe('Beber agua')
    })

    it('displays the habit executions', () => {
        expect(wrapper.find('#executions').text()).toBe('1 / 3 veces')
    })
})

[ ./resources/js/components/Habit/Info.vue ]

<script setup>
import { transChoice } from 'laravel-vue-i18n';

defineProps({
    name: {
        type: String,
    },
    executions_count: {
        type: Number,
    },
    times_per_day: {
        type: Number,
    },
})
</script>

<template>
    <div class="flex flex-col basis-1/2">
        <h2 id="name" class="text-base font-semibold">{{ name }}</h2>
        <div class="flex">
            <small id="executions" class="font-normal text-gray-500">{{ executions_count }} / {{ times_per_day }} {{ transChoice('habits.index.list.times_per_day', times_per_day) }}</small>
        </div>
    </div>
</template>

imagen imagen

It seems that it is necessary to inject the package on the test ... It seems that the problem is something similar that the one comented on this post. And, maybe, the solution is quite similar. But I don´t know how to act with your package.

So, do you know hao to solve the problem?

Greetings.

xiCO2k commented 1 month ago

will need to dig in a bit on this. Also if you find a way, let me know.

Thanks

zacktagnan commented 1 month ago

will need to dig in a bit on this. Also if you find a way, let me know.

Thanks

OK... I will be attentive to any contribution you come to in your deepening of the case. Regards.