Skip to content

Commit 41648e3

Browse files
committed
test: add test for properties watching
1 parent d145ae4 commit 41648e3

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/composables/__tests__/usePropsAsObjectProperties.spec.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import usePropsAsObjectProperties from "../usePropsAsObjectProperties";
3-
import { isReactive, isRef, reactive, ref } from "vue";
3+
import { defineComponent, isReactive, isRef, reactive, ref, watch } from "vue";
4+
import { flushPromises, mount, shallowMount } from "@vue/test-utils";
45

56
describe("usePropsAsObjectProperties", () => {
67
it("should return a reactive object", () => {
@@ -29,4 +30,37 @@ describe("usePropsAsObjectProperties", () => {
2930
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3031
expect((properties as any).styles).toBeUndefined();
3132
});
33+
34+
it("should update returning properties when input props are changing", () => {
35+
const props = reactive({ foo: "bar" });
36+
const properties = usePropsAsObjectProperties(props);
37+
38+
props.foo = "baz";
39+
40+
expect(properties.foo).toEqual("baz");
41+
});
42+
43+
it("should be possible to watch resulting properties and register changes on the input props", async () => {
44+
const WrapperComponent = defineComponent({
45+
props: ["foo", "style"],
46+
setup(props) {
47+
const watchFired = ref(false);
48+
const properties = usePropsAsObjectProperties(props);
49+
50+
watch(properties, () => {
51+
watchFired.value = true;
52+
});
53+
return {
54+
watchFired,
55+
};
56+
},
57+
});
58+
59+
const wrapper = shallowMount(WrapperComponent, {
60+
propsData: { foo: "initial" },
61+
});
62+
await wrapper.setProps({ foo: "updated" });
63+
64+
expect(wrapper.vm.watchFired).toEqual(true);
65+
});
3266
});

0 commit comments

Comments
 (0)