Skip to content

Commit

Permalink
fix(jest): add missing methods to mock
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Oct 2, 2023
1 parent a66e51a commit 2854265
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions jest/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ if (!NativeModules.RNWhisper) {
releaseContext: jest.fn(() => Promise.resolve()),
releaseAllContexts: jest.fn(() => Promise.resolve()),

// iOS AudioSession utils
getAudioSessionCurrentCategory: jest.fn(() => Promise.resolve({
category: 'AVAudioSessionCategoryPlayAndRecord',
options: [],
})),
getAudioSessionCurrentMode: jest.fn(() => Promise.resolve('')),
setAudioSessionCategory: jest.fn(() => Promise.resolve()),
setAudioSessionMode: jest.fn(() => Promise.resolve()),
setAudioSessionActive: jest.fn(() => Promise.resolve()),

// For NativeEventEmitter
addListener: jest.fn(),
removeListeners: jest.fn(),
Expand Down
14 changes: 12 additions & 2 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initWhisper, releaseAllWhisper } from '..'
import { initWhisper, releaseAllWhisper, AudioSessionIos } from '..'

jest.mock('..', () => require('../../jest/mock'))

Expand All @@ -16,7 +16,17 @@ test('Mock', async () => {
segments: [{ text: ' Test', t0: 0, t1: 33 }],
})

const { subscribe } = await context.transcribeRealtime()
const { subscribe } = await context.transcribeRealtime({
audioSessionOnStartIos: {
category: AudioSessionIos.Category.PlayAndRecord,
options: [
AudioSessionIos.CategoryOption.MixWithOthers,
AudioSessionIos.CategoryOption.AllowBluetooth,
],
mode: AudioSessionIos.Mode.Default,
},
audioSessionOnStopIos: 'restore',
})
const events: any[] = []
subscribe((event) => events.push(event))
await new Promise((resolve) => setTimeout(resolve, 0))
Expand Down

0 comments on commit 2854265

Please sign in to comment.