-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(SDK-2468] - update unit test imports
test(SDK-2468] - update unit test imports
- Loading branch information
1 parent
77693c7
commit a05009f
Showing
5 changed files
with
102 additions
and
28 deletions.
There are no files selected for viewing
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,11 @@ | ||
import { Platform, NativeModules } from 'react-native'; | ||
|
||
let RNBranch; | ||
|
||
if (Platform.OS === 'ios' || Platform.OS === 'android') { | ||
RNBranch = NativeModules.RNBranch; | ||
} else { | ||
throw new Error('Unsupported platform'); | ||
} | ||
|
||
export default RNBranch; |
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
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
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
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,65 @@ | ||
import { Platform, NativeModules } from 'react-native'; | ||
|
||
describe('RNBranch module', () => { | ||
let originalPlatform; | ||
let originalRNBranch; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
originalPlatform = Platform.OS; | ||
originalRNBranch = NativeModules.RNBranch; | ||
}); | ||
|
||
afterEach(() => { | ||
Platform.OS = originalPlatform; | ||
NativeModules.RNBranch = originalRNBranch; | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe('Platform-specific tests', () => { | ||
it('should use NativeModules.RNBranch for iOS', () => { | ||
Platform.OS = 'ios'; | ||
NativeModules.RNBranch = { mockInit: jest.fn() }; | ||
|
||
const RNBranch = require('../src/RNBranch').default; | ||
expect(RNBranch).not.toBeNull(); | ||
expect(RNBranch).toBe(NativeModules.RNBranch); | ||
}); | ||
|
||
it('should use NativeModules.RNBranch for Android', () => { | ||
Platform.OS = 'android'; | ||
NativeModules.RNBranch = { mockInit: jest.fn() }; | ||
|
||
const RNBranch = require('../src/RNBranch').default; | ||
expect(RNBranch).not.toBeNull(); | ||
expect(RNBranch).toBe(NativeModules.RNBranch); | ||
}); | ||
|
||
it('should throw an error for unsupported platforms', () => { | ||
Platform.OS = 'unsupportedPlatform'; | ||
|
||
expect(() => { | ||
require('../src/RNBranch'); | ||
}).toThrow('Unsupported platform'); | ||
}); | ||
}); | ||
|
||
describe('Null tests', () => { | ||
it('should be null when NativeModules.RNBranch is null for iOS', () => { | ||
Platform.OS = 'ios'; | ||
NativeModules.RNBranch = null; | ||
|
||
const RNBranch = require('../src/RNBranch').default; | ||
expect(RNBranch).toBeNull(); | ||
}); | ||
|
||
it('should be null when NativeModules.RNBranch is null for Android', () => { | ||
Platform.OS = 'android'; | ||
NativeModules.RNBranch = null; | ||
|
||
const RNBranch = require('../src/RNBranch').default; | ||
expect(RNBranch).toBeNull(); | ||
}); | ||
}); | ||
}); | ||
|