Skip to content

Commit

Permalink
fix(core): createObserveDocument tests use vitest, add listener name
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Jan 14, 2025
1 parent 34e02e1 commit bf43325
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {describe, expect, it, jest} from '@jest/globals'
import {createClient, type WelcomeEvent} from '@sanity/client'
import {firstValueFrom, of, skip, Subject} from 'rxjs'
import {take} from 'rxjs/operators'
import {describe, expect, it, vi} from 'vitest'

import {createObserveDocument, type ListenerMutationEventLike} from '../createObserveDocument'

Expand All @@ -14,10 +14,10 @@ describe(createObserveDocument.name, () => {
useCdn: false,
})

jest
.spyOn(mockedClient.observable, 'fetch')
.mockImplementation(() => of([{_id: 'foo', fetched: true}]) as any)
jest.spyOn(mockedClient, 'withConfig').mockImplementation(() => mockedClient)
vi.spyOn(mockedClient.observable, 'fetch').mockImplementation(
() => of([{_id: 'foo', fetched: true}]) as any,
)
vi.spyOn(mockedClient, 'withConfig').mockImplementation(() => mockedClient)

const mutationChannel = new Subject<WelcomeEvent | ListenerMutationEventLike>()

Expand All @@ -28,7 +28,7 @@ describe(createObserveDocument.name, () => {

const initial = firstValueFrom(observeDocument('foo').pipe(take(1)))

mutationChannel.next({type: 'welcome'})
mutationChannel.next({type: 'welcome', listenerName: 'preview.global'})

expect(await initial).toEqual({_id: 'foo', fetched: true})
})
Expand All @@ -41,8 +41,8 @@ describe(createObserveDocument.name, () => {
useCdn: false,
})

jest.spyOn(mockedClient.observable, 'fetch').mockImplementation(() => of([]) as any)
jest.spyOn(mockedClient, 'withConfig').mockImplementation(() => mockedClient)
vi.spyOn(mockedClient.observable, 'fetch').mockImplementation(() => of([]) as any)
vi.spyOn(mockedClient, 'withConfig').mockImplementation(() => mockedClient)

const mutationChannel = new Subject<WelcomeEvent | ListenerMutationEventLike>()

Expand All @@ -53,7 +53,7 @@ describe(createObserveDocument.name, () => {

const initial = firstValueFrom(observeDocument('foo').pipe(take(1)))

mutationChannel.next({type: 'welcome'})
mutationChannel.next({type: 'welcome', listenerName: 'preview.global'})

expect(await initial).toEqual(undefined)
})
Expand All @@ -66,7 +66,7 @@ describe(createObserveDocument.name, () => {
useCdn: false,
})

jest.spyOn(mockedClient.observable, 'fetch').mockImplementation(
vi.spyOn(mockedClient.observable, 'fetch').mockImplementation(
() =>
of([
{
Expand All @@ -79,7 +79,7 @@ describe(createObserveDocument.name, () => {
},
]) as any,
)
jest.spyOn(mockedClient, 'withConfig').mockImplementation(() => mockedClient)
vi.spyOn(mockedClient, 'withConfig').mockImplementation(() => mockedClient)

const mutationChannel = new Subject<WelcomeEvent | ListenerMutationEventLike>()

Expand All @@ -90,7 +90,7 @@ describe(createObserveDocument.name, () => {

const final = firstValueFrom(observeDocument('1c32390c').pipe(skip(1), take(1)))

mutationChannel.next({type: 'welcome'})
mutationChannel.next({type: 'welcome', listenerName: 'preview.global'})
mutationChannel.next({
type: 'mutation',
documentId: '1c32390c',
Expand Down

0 comments on commit bf43325

Please sign in to comment.