Skip to content

Commit

Permalink
Consolidate mocks, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Dec 17, 2024
1 parent 88c49ee commit 0a549b8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
16 changes: 16 additions & 0 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,19 @@ jest.mock('expo-modules-core', () => ({
return () => null
}),
}))

jest.mock('expo-localization', () => ({
getLocales: () => [],
}))

jest.mock('statsig-react-native-expo', () => ({
Statsig: {
initialize() {},
initializeCalled() {
return false
},
},
}))

jest.mock('../src/lib/bitdrift', () => ({}))
jest.mock('../src/lib/statsig/statsig', () => ({}))
26 changes: 12 additions & 14 deletions src/lib/bitdrift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import {initPromise} from './statsig/statsig'

const BITDRIFT_API_KEY = process.env.BITDRIFT_API_KEY

if (process.env.NODE_ENV !== 'test') {
initPromise.then(() => {
let isEnabled = false
try {
if (Statsig.checkGate('enable_bitdrift')) {
isEnabled = true
}
} catch (e) {
// Statsig may complain about it being called too early.
initPromise.then(() => {
let isEnabled = false
try {
if (Statsig.checkGate('enable_bitdrift')) {
isEnabled = true
}
if (isEnabled && BITDRIFT_API_KEY) {
init(BITDRIFT_API_KEY, {url: 'https://api-bsky.bitdrift.io'})
}
})
}
} catch (e) {
// Statsig may complain about it being called too early.
}
if (isEnabled && BITDRIFT_API_KEY) {
init(BITDRIFT_API_KEY, {url: 'https://api-bsky.bitdrift.io'})
}
})
13 changes: 0 additions & 13 deletions src/state/session/__tests__/session-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,12 @@ import {describe, expect, it, jest} from '@jest/globals'
import {agentToSessionAccountOrThrow} from '../agent'
import {Action, getInitialState, reducer, State} from '../reducer'

jest.mock('statsig-react-native-expo', () => ({
Statsig: {
initialize() {},
initializeCalled() {
return false
},
},
}))

jest.mock('jwt-decode', () => ({
jwtDecode(_token: string) {
return {}
},
}))

jest.mock('expo-localization', () => ({
getLocales: () => [],
}))

describe('session', () => {
it('can log in and out', () => {
let state = getInitialState([])
Expand Down

0 comments on commit 0a549b8

Please sign in to comment.