-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from PrefectHQ/fix-use-subscription-with-depe…
…ndency-reactivity Fix subscription actions being called even when the args have not changed
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/useSubscription/useSubscriptionWithDependencies.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { expect, test, vi } from 'vitest' | ||
import { computed, ref } from 'vue' | ||
import { useSubscriptionWithDependencies } from '@/useSubscription/useSubscriptionWithDependencies' | ||
import { timeout } from '@/utilities/tests' | ||
|
||
test('it does not execute the action when args have not changed', async () => { | ||
const object = ref({ value: 0 }) | ||
const action = vi.fn() | ||
|
||
const parameters = computed(() => [object.value]) | ||
|
||
useSubscriptionWithDependencies(action, parameters) | ||
|
||
await timeout() | ||
|
||
expect(action).toBeCalledTimes(1) | ||
|
||
object.value = { value: 1 } | ||
|
||
await timeout() | ||
|
||
expect(action).toBeCalledTimes(2) | ||
|
||
object.value = { value: 1 } | ||
|
||
await timeout() | ||
|
||
expect(action).toBeCalledTimes(2) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters