Skip to content

Commit

Permalink
🛠️: refactor FormRadio test to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
itisAliRH committed Apr 5, 2024
1 parent a543b04 commit fb40913
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { mount } from "@vue/test-utils";
import { getLocalVue } from "tests/jest/helpers";
import { getLocalVue } from "@tests/jest/helpers";
import { mount, Wrapper } from "@vue/test-utils";

import MountTarget from "./FormRadio";
import MountTarget from "./FormRadio.vue";

const localVue = getLocalVue(true);

describe("FormRadio", () => {
let wrapper;
let wrapper: Wrapper<Vue>;

beforeEach(() => {
wrapper = mount(MountTarget, {
wrapper = mount(MountTarget as object, {
propsData: {
value: false,
options: [],
Expand All @@ -20,21 +20,30 @@ describe("FormRadio", () => {

it("basics", async () => {
const noInput = wrapper.find("[type='radio']");

expect(noInput.exists()).toBe(false);

const n = 3;
const options = [];

for (let i = 0; i < n; i++) {
options.push({ label: `label_${i}`, value: `value_${i}` });
}

await wrapper.setProps({ options });

const inputs = wrapper.findAll("[type='radio']");
const labels = wrapper.findAll(".custom-control-label");

expect(inputs.length).toBe(n);

for (let i = 0; i < n; i++) {
await inputs.at(i).setChecked();

expect(labels.at(i).text()).toBe(`label_${i}`);
expect(inputs.at(i).attributes("value")).toBe(`value_${i}`);
expect(wrapper.emitted()["input"][i][0]).toBe(`value_${i}`);

expect(wrapper.emitted()["input"]?.[i]?.[0]).toBe(`value_${i}`);
}
});
});

0 comments on commit fb40913

Please sign in to comment.