|
1 | 1 | import { describe, expect, it } from "vitest";
|
2 | 2 | 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"; |
4 | 5 |
|
5 | 6 | describe("usePropsAsObjectProperties", () => {
|
6 | 7 | it("should return a reactive object", () => {
|
@@ -29,4 +30,37 @@ describe("usePropsAsObjectProperties", () => {
|
29 | 30 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
30 | 31 | expect((properties as any).styles).toBeUndefined();
|
31 | 32 | });
|
| 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 | + }); |
32 | 66 | });
|
0 commit comments