Closed mpont91 closed 2 years ago
I tried to contribute solving this problem. I thought this code would work:
packages/unit-vitest/src/helpers/layout-injections.ts
/**
* Injections for Components with a QPage root Element
*/
export function qLayoutInjections() {
return {
// pageContainerKey
_q_pc_: true,
// layoutKey
_q_l_: {
header: { size: 0, offset: 0, space: false },
right: { size: 300, offset: 0, space: false },
footer: { size: 0, offset: 0, space: false },
left: { size: 300, offset: 0, space: false },
isContainer: false,
view: 'hhh lpr fff' // Added this line
},
};
}
But the same error keeps appearing... What am I doing wrong? Seems that is not injecting...
You probably need to add view: { value: 'hhh lpr fff' }
, since Quasar expects that to be a ref
and access it as layout.view.value
I haven't switched to using '@quasar/quasar-app-extension-testing-unit-vitest'
yet, but I based my own install-quasar-plugin.ts
on the original work from that PR. Here's what worked for me. Note that some of the layout values are probably not 100% valid, but it got things working 😄 :
export function installQuasar(options?: Partial<QuasarPluginOptions>) {
const globalConfigBackup = cloneDeep(config.global);
beforeAll(() => {
// Mock out uid implementation so that snapshots will work and won't generate a new ID on form elements
vi.spyOn(uid, 'default').mockImplementation(() => 'quasar-uid');
config.global.plugins.unshift([Quasar, options]);
config.global.provide._q_l_ = {
header: { size: 1200, offset: 0, space: false },
right: { size: 1200, offset: 0, space: false },
footer: { size: 1200, offset: 0, space: false },
left: { size: 1200, offset: 0, space: false },
view: ref('lHh Lpr lff'),
rows: ref({ top: 'lHh', bottom: 'Lpr', left: 0, right: 0 }),
instances: ref({}),
isContainer: ref(false),
update: vi.fn(),
animate: vi.fn(),
totalWidth: ref(1200),
scroll: ref({ position: 0, direction: 'up' }),
scrollbarWidth: ref(125)
};
});
afterAll(() => {
config.global = globalConfigBackup;
});
}
If anyone wants to use what I have to open a PR, feel free! Otherwise, I can try to open a PR later today.
You probably need to add
view: { value: 'hhh lpr fff' }
, since Quasar expects that to be aref
and access it aslayout.view.value
Oh it's just I based on isContainer
property. shouldn't be isContainer: { value: false }
as well? 😅
I tried using refs like @jdk2pq but when I run npm run sync:vitest
it fails with this message repeatly:
[5/5] 🔨 Building fresh packages...
$ rimraf dist && tsc --declaration --declarationDir dist/types
../../node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1960:9 - error TS2451: Cannot redeclare block-scoped variable 'defineProps'.
1960 const defineProps: _defineProps
~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:2014:9
2014 const defineProps: _defineProps
~~~~~~~~~~~
'defineProps' was also declared here.
../../node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1961:9 - error TS2451: Cannot redeclare block-scoped variable 'defineEmits'.
1961 const defineEmits: _defineEmits
~~~~~~~~~~~
So we have to transform all ref()
to {value: xxx}
?
I see there is no PR yet, so I'll do it with @jdk2pq help :D
Software version
OS: MacBook Pro M1 - v12.4 Node: 16.15.1 NPM: 8.11.0
What did you get as the error?
An exception:
What were you expecting?
Pass the tests.
What steps did you take, to get the error?
src/components/TheHeaderComponent.vue
src/components/TheFooterComponent.vue
test/vitest/__tests__/TheHeaderComponent.spec.js
test/vitest/__tests__/TheFooterComponent.spec.js
If I remove the QHeader and QFooter components the tests pass:
src/components/TheFooterComponent.vue