Skip to content

Commit 27df868

Browse files
committed
vue: add jest testing hints on imports and add exports to package.json
- Add documentation on import order for jest (or other) unit tests using CJS transformations - Add explicit `exports` property to vue's package.json to facilitate tools finding the correct bundle Mitigates #2250
1 parent 31b9a7a commit 27df868

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packages/vue/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,27 @@ const myComponent = defineComponent({
289289
The injected `jsonforms` object is not meant to be modified directly.
290290
Instead it should be modified via the provided `dispatch` and by changing the props of the `json-forms` component.
291291

292+
### Testing with Jest / Vitest
293+
294+
When testing custom renderers with Jest or Vitest using CJS transforms, `vue` must be imported **before** `@jsonforms/vue` in your renderer files.
295+
This is due to the CJS bundle eagerly evaluating Vue component definitions at `require()` time, which can cause issues when Jest's module resolution processes imports sequentially.
296+
297+
```ts
298+
// Correct - import vue before @jsonforms/vue
299+
import { defineComponent } from 'vue';
300+
import { rendererProps, useJsonFormsControl } from '@jsonforms/vue';
301+
```
302+
303+
```ts
304+
// May cause errors in tests:
305+
// "Property 'controlWrapper' was accessed during render but is not defined on instance"
306+
import { rendererProps, useJsonFormsControl } from '@jsonforms/vue';
307+
import { defineComponent } from 'vue';
308+
```
309+
310+
This only affects test environments using CJS module transforms.
311+
Browser builds using Webpack, Vite, or other ESM-aware bundlers are not affected.
312+
292313
## License
293314

294315
The JSON Forms project is licensed under the MIT License. See the [LICENSE file](https://github.com/eclipsesource/jsonforms/blob/master/LICENSE) for more information.

packages/vue/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
"main": "lib/jsonforms-vue.cjs.js",
3535
"module": "lib/jsonforms-vue.esm.js",
3636
"types": "lib/index.d.ts",
37+
"exports": {
38+
".": {
39+
"import": "./lib/jsonforms-vue.esm.js",
40+
"require": "./lib/jsonforms-vue.cjs.js",
41+
"types": "./lib/index.d.ts"
42+
}
43+
},
3744
"files": [
3845
"lib/*",
3946
"src/*"

0 commit comments

Comments
 (0)