Skip to content

Commit 68d5edb

Browse files
committed
Extract createMockSubscription()
1 parent b2dfce2 commit 68d5edb

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/components/schedule/auto-mode/auto-mode-button/__tests__/use-pulling.spec.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ const AUTO_MODE_STATES = [
2121

2222
const fcAutoModeState = () => fc.constantFrom(...AUTO_MODE_STATES);
2323

24+
type Sub = ReturnType<typeof useSubscribeScheduleAutoModeState>;
25+
26+
function createMockSubscription(auto_mode_state: string): Sub {
27+
// Initially `undefined`
28+
const autoModeState = ref(undefined as string | undefined);
29+
30+
// A value set when ready
31+
const ready = (async () => {
32+
await Promise.resolve();
33+
autoModeState.value = auto_mode_state;
34+
})();
35+
36+
// Thenable
37+
return onReady({ autoModeState }, ready) as Sub;
38+
}
39+
2440
describe("usePulling()", () => {
2541
beforeEach(() => {
2642
vi.clearAllMocks();
@@ -33,22 +49,8 @@ describe("usePulling()", () => {
3349
it("Property test", async () => {
3450
await fc.assert(
3551
fc.asyncProperty(fcAutoModeState(), async (auto_mode_state) => {
36-
// Initially `undefined`
37-
const autoModeState = ref(undefined as string | undefined);
38-
39-
// A value set when ready
40-
const ready = (async () => {
41-
await Promise.resolve();
42-
autoModeState.value = auto_mode_state;
43-
})();
44-
45-
type Sub = ReturnType<typeof useSubscribeScheduleAutoModeState>;
46-
47-
// Thenable
48-
const sub = onReady({ autoModeState }, ready) as unknown as Sub;
49-
52+
const sub = createMockSubscription(auto_mode_state);
5053
vi.mocked(useSubscribeScheduleAutoModeState).mockReturnValue(sub);
51-
5254
const { pulling } = await usePulling();
5355
const expected = auto_mode_state === "auto_pulling";
5456
expect(pulling.value).toBe(expected);

0 commit comments

Comments
 (0)