Skip to content

TypeError: Cannot read property 'getRandomBase64' of undefined ] #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hogehoge-satosato opened this issue Jan 6, 2021 · 6 comments
Closed

Comments

@hogehoge-satosato
Copy link

こんにちは、React Nativeの本の読者です。

P544~545をコードにしているのですが、UUIDがうまくいかず、タイトルのエラーが出ます。
Jestによるテストが進まず、困っています。

色々調べてためしたのですが、うまくいきません。
https://stackoverflow.com/questions/64165922/error-cannot-read-property-getrandombase64-of-undefined-when-running-test-file
↑ を試しましたが、だめでした。
こちらのGitHubに提供されているコードを丸コピーして入れてもうまくいきませんでした。

アプリの実相のこれまでのところは、うまくいっていました。

こちらはかなりの初心者です。
八方ふさがりで困っています。
心苦しいのですが、ご助言いただけますと助かります。

環境は、Windows10HOME
エディタは、VSCodeです。
よろしくお願いします。

@hogehoge-satosato
Copy link
Author

スクリーンショット 2021-01-06 103001

コマンドプロンプトのエラー画面です。
VSCodeでも同じです。

@kyamashiro
Copy link

package.jsonのreact-native-get-random-valuesのバージョンは"1.3.0"でしょうか?
こちらの環境で試したところ"1.4.0","1.5.0"だとテストでエラーになるようです。

_mocks_ディレクトリ直下に空のreact-native-get-random-values.jsファイルを作成するか、もしくはこちらのissueにあるようにテストファイル内のdescribeの前に

jest.mock('react-native-get-random-values', () => ({
  getRandomBase64: jest.fn(),
}));

モックを追加してあげればテストで失敗しなくなるようです。

@hogehoge-satosato
Copy link
Author

hogehoge-satosato commented Jan 8, 2021 via email

@hogehoge-satosato
Copy link
Author

ターミナルで
yarn add [email protected]
実行したところ、うまくいきました!!
すごく助かりました。
ありがとうございます(T T)

@januswel
Copy link
Member

@hogehoge-satosato
ご連絡ありがとうございます
確認が遅くなってすみません
いただいた情報は編集に連絡して正誤表に載せてもらいます

@kyamashiro
フォローありがとうございます

@hogehoge-satosato
Copy link
Author

hogehoge-satosato commented Jan 11, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants