JEST avec EXPO+ react-native-async-storage + native base => marche pas

29/03/2022

installer

expo install jest-expo jest
npm install -D react-test-renderer@17.0.1

dans package.json

"scripts": {
    "test": "jest"
},
"jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
        "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|.*native-base.*|react-native-svg)"
    ],
    "setupFiles": ["./jestSetupFile.js"]
},

dans jestSetupFile.js

import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';

jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);

dans App.test

import React from 'react';
import renderer from 'react-test-renderer';

import App from './App.js';

describe('', () => {
    it('has 1 child', () => {
        const tree = renderer.create(
            
        ).toJSON();
        if (tree.children === null)
            console.log('TREE CHILDREN IS NULL');
        else
            console.log('TREE CHILDREN has data', tree.children.length, tree.children);
        // expect(tree.children.length).toBe(1);
    });
});

const inset = {
    frame: { x: 0, y: 0, width: 0, height: 0 },
    insets: { top: 0, left: 0, right: 0, bottom: 0 },
};

copier partout

cp /root/docker/gextrasign/App.test.js jestSetupFile.js /root/docker/gextrasale
cp /root/docker/gextrasign/App.test.js jestSetupFile.js /root/docker/gextrareact
cp /root/docker/gextrasign/App.test.js jestSetupFile.js /root/docker/gextratime
cp /root/docker/gextrasign/App.test.js jestSetupFile.js /root/docker/flatbayreact

lancer

npm run test