initialWindowMetrics-test.tsx 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { UIManager } from 'react-native';
  2. import { Metrics } from '../SafeArea.types';
  3. describe('initialWindowMetrics', () => {
  4. it('is null when no view config is available', () => {
  5. jest.resetModules();
  6. expect(require('../initialWindowMetrics').initialWindowMetrics).toBe(null);
  7. });
  8. it('it uses the constant provided by the view config', () => {
  9. jest.resetModules();
  10. const testMetrics: Metrics = {
  11. insets: {
  12. top: 20,
  13. left: 0,
  14. right: 0,
  15. bottom: 0,
  16. },
  17. frame: {
  18. x: 0,
  19. y: 0,
  20. height: 100,
  21. width: 100,
  22. },
  23. };
  24. UIManager.getViewManagerConfig = jest.fn((name) => {
  25. if (name === 'RNCSafeAreaView') {
  26. return {
  27. Commands: {},
  28. Constants: {
  29. initialWindowMetrics: testMetrics,
  30. },
  31. };
  32. }
  33. return { Commands: {} };
  34. });
  35. expect(require('../index').initialWindowMetrics).toBe(testMetrics);
  36. expect(UIManager.getViewManagerConfig).toBeCalledWith('RNCSafeAreaView');
  37. });
  38. });