我一直试图让Jest使用我的反应原生项目而没有太多运气.似乎大多数线程都是被黑客攻击的解决方案,以便让事情正常运行,我似乎无法克服我面临的最后一个障碍.
尝试运行以下代码时,我收到以下错误.如果我在jestSupport/env.js文件中模拟react-native我可以通过错误,但显然我不能使用任何结构(如AsyncStorage)来实际测试我的代码(因为我只有模拟功能).
有没有人对如何解决这个问题有任何建议?
在这个阶段,我愿意尝试任何事情,包括废弃我所拥有的所有测试,然后再试一次.如果是这种情况,我需要遵循一些指导原则,因为React Native文档在Jest方面可能已经过时,而且我对React场景相对较新.
Runtime Error
Error: Cannot find module 'ReactNative' from 'react-native.js'
at Runtime._resolveNodeModule (/Users/Yulfy/Downloads/COMPANY-Mobile/node_modules/jest-cli/src/Runtime/Runtime.js:451:11)
at Object.<anonymous> (/Users/Yulfy/Downloads/COMPANY-Mobile/node_modules/react-native/Libraries/react-native/react-native.js:181:25)
at Object.<anonymous> (/Users/Yulfy/Downloads/COMPANY-Mobile/network/connections.js:8:18)
Run Code Online (Sandbox Code Playgroud)
jest.unmock('../network/connections');
import Authorisation from '../network/connections';
describe('connections', () => {
it('Should store and retrieve a mocked user object', () => {
Auth = new Authorisation();
const TEST_STRING = "CONNECTION TEST PASS";
var userObj = {
test_string: TEST_STRING
};
Auth._localStore(userObj, (storeRes) => {
Auth._localRetrieve((retRes) => {
expect(retRes.test_string).toEqual(TEST_STRING);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
/*
* All …Run Code Online (Sandbox Code Playgroud) 我想知道Math.random()Java背后 PRNG* 的默认种子是什么。据我了解,C 中的那个是基于系统时钟的。那么它在Java中是否相似?另外,每次Math.random()调用时种子都会改变吗?
*PRNG = 伪随机数生成器