Skip to content

Commit 809f246

Browse files
committed
feat(cursors): better unit chore-execution test output
1 parent 9309a80 commit 809f246

File tree

5 files changed

+16
-32
lines changed

5 files changed

+16
-32
lines changed

packages/qwik/src/core/reactive-primitives/impl/signal.unit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { $, _wrapProp, isBrowser } from '@qwik.dev/core';
22
import { createDocument } from '@qwik.dev/core/testing';
3-
import { afterEach, beforeEach, describe, expect, expectTypeOf, it, vi } from 'vitest';
3+
import { afterEach, beforeEach, describe, expect, expectTypeOf, it } from 'vitest';
44
import { getDomContainer } from '../../client/dom-container';
55
import { implicit$FirstArg } from '../../shared/qrl/implicit_dollar';
66
import { inlinedQrl } from '../../shared/qrl/qrl';

packages/qwik/src/core/shared/cursor/chore-execution.unit.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ vi.mock('../component-execution', () => ({
5353

5454
vi.mock('../utils/styles', () => ({
5555
serializeAttribute: vi.fn((property: string, value: any) => {
56-
if (value == null) return null;
56+
if (value == null) {
57+
return null;
58+
}
5759
return String(value);
5860
}),
5961
}));
@@ -397,9 +399,13 @@ describe('executeComponentChore', () => {
397399
throw error;
398400
});
399401

402+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
403+
400404
executeComponentChore(vNode, container, journal, cursor);
401405

402406
expect(container.handleError).toHaveBeenCalledWith(error, vNode);
407+
408+
consoleErrorSpy.mockRestore();
403409
});
404410

405411
it('should return promise if execution is async', async () => {

packages/qwik/src/core/shared/cursor/cursor-queue.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import type { Cursor } from './cursor';
1111
import { getCursorData } from './cursor-props';
1212

1313
/** Global cursor queue array. Cursors are sorted by priority. */
14-
let globalCursorQueue: Cursor[] = [];
14+
const globalCursorQueue: Cursor[] = [];
1515

16-
let pausedCursorQueue: Cursor[] = [];
16+
const pausedCursorQueue: Cursor[] = [];
1717

1818
/**
1919
* Adds a cursor to the global queue. If the cursor already exists, it's removed and re-added to
@@ -108,26 +108,3 @@ export function removeCursorFromQueue(
108108
globalCursorQueue.splice(index, 1);
109109
}
110110
}
111-
112-
/**
113-
* Checks if the global cursor queue is empty.
114-
*
115-
* @returns True if the queue is empty
116-
*/
117-
export function isCursorQueueEmpty(): boolean {
118-
return globalCursorQueue.length === 0;
119-
}
120-
121-
/**
122-
* Gets the number of cursors in the global queue.
123-
*
124-
* @returns The number of cursors
125-
*/
126-
export function getCursorQueueSize(): number {
127-
return globalCursorQueue.length;
128-
}
129-
130-
/** Clears all cursors from the global queue. */
131-
export function clearCursorQueue(): void {
132-
globalCursorQueue = [];
133-
}

packages/qwik/src/core/tests/projection.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { vnode_getProp, vnode_locate } from '../client/vnode-utils';
2525
import { HTML_NS, QContainerAttr, QDefaultSlot, SVG_NS } from '../shared/utils/markers';
2626
import { QContainerValue } from '../shared/types';
2727
import { VNodeFlags } from '../client/types';
28-
import { VirtualVNode } from '../client/vnode-impl';
28+
import { VirtualVNode } from '../shared/vnode/virtual-vnode';
2929

3030
const DEBUG = false;
3131

@@ -1589,7 +1589,7 @@ describe.each([
15891589
{ debug: DEBUG }
15901590
);
15911591
expect((vNode!.flags & VNodeFlags.Resolved) === VNodeFlags.Resolved).toBe(true);
1592-
expect(vnode_getProp(vNode, QDefaultSlot, null)).toBeInstanceOf(VirtualVNode);
1592+
expect(vnode_getProp(vNode!, QDefaultSlot, null)).toBeInstanceOf(VirtualVNode);
15931593
});
15941594
});
15951595

packages/qwik/src/core/tests/use-visible-task.spec.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { delay } from '../shared/utils/promises';
2222
import { ELEMENT_SEQ } from '../../server/qwik-copy';
2323
import { Task, TaskFlags } from '../use/use-task';
2424
import { USE_ON_LOCAL } from '../shared/utils/markers';
25+
import { vnode_getProp } from '../client/vnode-utils';
2526

2627
const debug = false; //true;
2728
Error.stackTraceLimit = 100;
@@ -819,21 +820,21 @@ describe.each([
819820
if (render === ssrRenderToDom) {
820821
await trigger(document.body, 'div', 'qvisible');
821822
}
822-
const seq = vNode!.getProp<any[]>(ELEMENT_SEQ, container.$getObjectById$)!;
823+
const seq = vnode_getProp<any[]>(vNode!, ELEMENT_SEQ, container.$getObjectById$)!;
823824
const task = seq.find((task) => task instanceof Task)!;
824825
expect((task.$flags$ & TaskFlags.EVENTS_REGISTERED) === TaskFlags.EVENTS_REGISTERED).toBe(
825826
false
826827
);
827828
if (render === ssrRenderToDom) {
828829
// only on SSR after resuming we have no useOn props
829-
expect(vNode!.getProp(USE_ON_LOCAL, null)).toBeNull();
830+
expect(vnode_getProp<any>(vNode!, USE_ON_LOCAL, null)).toBeNull();
830831
}
831832

832833
await trigger(document.body, 'button', 'click');
833834
expect((task.$flags$ & TaskFlags.EVENTS_REGISTERED) === TaskFlags.EVENTS_REGISTERED).toBe(
834835
true
835836
);
836-
expect(vNode!.getProp(USE_ON_LOCAL, null)).not.toBeNull();
837+
expect(vnode_getProp<any>(vNode!, USE_ON_LOCAL, null)).not.toBeNull();
837838
});
838839

839840
it('#1717 - custom hooks should work', async () => {

0 commit comments

Comments
 (0)