-
-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZulipAsyncStorage: Add a test for
setItem
.
With a new mock for `TextCompressionModule`; we do that globally in case it's useful elsewhere. That module should grow its own set of unit tests.
- Loading branch information
1 parent
8d23f74
commit 60303c7
Showing
2 changed files
with
40 additions
and
0 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
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,33 @@ | ||
/* @flow strict-local */ | ||
import { NativeModules, Platform } from 'react-native'; | ||
import AsyncStorage from '@react-native-community/async-storage'; | ||
|
||
import ZulipAsyncStorage from '../ZulipAsyncStorage'; | ||
|
||
// Some of these tests here are written to differ slightly between iOS | ||
// and Android, which might make them a bit harder to understand. But | ||
// most of the logic is appropriately in common between the platforms, | ||
// so we haven't split the different logic up into different tests. | ||
// | ||
// We may in the future decide to add (or replace this file with) a | ||
// `ZulipAsyncStorage-test.ios.js` and | ||
// `ZulipAsyncStorage-test.android.js`, to target entire test suites | ||
// to Android and iOS. | ||
describe('ZulipAsyncStorage', () => { | ||
describe('setItem', () => { | ||
const setItemSpy = jest.spyOn(AsyncStorage, 'setItem'); | ||
|
||
const key = 'foo!'; | ||
const value = '123!'; | ||
const callback = err => {}; | ||
|
||
test('calls AsyncStorage.setItem as we expect it to', async () => { | ||
await ZulipAsyncStorage.setItem(key, value, callback); | ||
|
||
const expectedValue = | ||
Platform.OS === 'ios' ? value : await NativeModules.TextCompressionModule.compress(value); | ||
expect(setItemSpy).toHaveBeenCalledTimes(1); | ||
expect(setItemSpy).toHaveBeenCalledWith(key, expectedValue, callback); | ||
}); | ||
}); | ||
}); |