This repository was archived by the owner on Oct 16, 2025. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add test coverage for the public API of the library.
The tests use an odd combination of Jest and testdouble.js mocking, but that's the only way I was able to make it work reasonably well.
Because react-native-sensitive-info is a native module, we have to mock/stub it out for testing. I use
jest.mockto do the module replacement, because I couldn't gettd.replaceto work properly despite several different attempts.Because babel-jest "hoists" the
jest.mockcall, I extracted the r-n-s-i mock into its own file so I could use testdouble'std.func()for the functions. testdouble gives a much better API for stubs and expectations as well as checking arguments by default, so I chose to use it for most of the stubbing/mocking.However, to stub out the platform detection code, I found it easier to use
jest.fn()because it allows you to specify a custom mock implementation where testdouble does not. That suggests that perhaps the platform dependency should be extracted into its own file, but I chose not to do that at this time since this is a single-file module at present.Along the way, I found several bugs in the code. In
getItem()we were trying to convert anyundefinedresponse into anullinstead in order to avoid a downstream exception, but it was too aggressive and was turning any "falsy" result intonull. Also, we weren't checking for the callback before calling it in some of the exception handlers. Those issues are now fixed.