Skip to content

Commit

Permalink
add js tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Nov 5, 2024
1 parent be04dfc commit 77691bd
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/core/test/replay/CustomMask.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { describe, expect, it, beforeEach } from '@jest/globals';

describe('CustomMask', () => {
beforeEach(() => {
jest.resetModules();
});

it('returns a fallback when native view manager is missing', () => {
jest.mock('react-native', () => ({
UIManager: {},
View: jest.fn(),
}));

const { Mask, Unmask } = require('../../src/js/replay/CustomMask');

expect(Mask).toBeDefined();
expect(Unmask).toBeDefined();
});

it('returns a fallback component when native view manager config is missing', () => {
jest.mock('react-native', () => ({
UIManager: {
hasViewManagerConfig: () => false,
},
View: jest.fn(),
}));

const { Mask, Unmask } = require('../../src/js/replay/CustomMask');

expect(Mask).toBeDefined();
expect(Unmask).toBeDefined();
});

it('returns native components when native components exist', () => {
const mockMaskComponent = jest.fn();
const mockUnmaskComponent = jest.fn();

jest.mock('../../src/js/RNSentryReplayMaskNativeComponent', () => ({
default: mockMaskComponent,
}));

jest.mock('../../src/js/RNSentryReplayUnmaskNativeComponent', () => ({
default: mockUnmaskComponent,
}));

jest.mock('react-native', () => ({
UIManager: {
hasViewManagerConfig: () => true,
},
View: jest.fn(),
}));

const { Mask, Unmask } = require('../../src/js/replay/CustomMask');

expect(Mask).toBe(mockMaskComponent);
expect(Unmask).toBe(mockUnmaskComponent);
});
});
10 changes: 10 additions & 0 deletions packages/core/test/replay/CustomMask.web.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe } from '@jest/globals';

describe('CustomMask', () => {
it('returns a react native view', () => {
const { Mask, Unmask } = require('../../src/js/replay/CustomMask');

expect(Mask).toBeDefined();
expect(Unmask).toBeDefined();
});
});

0 comments on commit 77691bd

Please sign in to comment.