|
1 | 1 | import type { NativeModule } from 'react-native'; |
2 | 2 | import type { MockInstance } from 'vitest'; |
3 | | -import { isNativeModuleLoaded, isValidCallback } from './helpers'; |
| 3 | +import { |
| 4 | + isNativeModuleLoaded, |
| 5 | + isObjectSerializable, |
| 6 | + isValidCallback, |
| 7 | +} from './helpers'; |
4 | 8 |
|
5 | 9 | describe('helpers', () => { |
6 | 10 | let errorSpy: MockInstance; |
@@ -58,4 +62,42 @@ describe('helpers', () => { |
58 | 62 | expect(result).toBe(true); |
59 | 63 | }); |
60 | 64 | }); |
| 65 | + |
| 66 | + describe('isObjectSerializable', () => { |
| 67 | + test.each([ |
| 68 | + { description: 'an empty object', value: {} }, |
| 69 | + { description: 'an object with string values', value: { key: 'value' } }, |
| 70 | + { description: 'an object with number values', value: { count: 42 } }, |
| 71 | + { description: 'an object with boolean values', value: { active: true } }, |
| 72 | + { description: 'an object with null values', value: { data: null } }, |
| 73 | + { |
| 74 | + description: 'a nested object', |
| 75 | + value: { outer: { inner: 'value' } }, |
| 76 | + }, |
| 77 | + { |
| 78 | + description: 'an object with array values', |
| 79 | + value: { items: [1, 2, 3] }, |
| 80 | + }, |
| 81 | + ])('should return true for $description', ({ value }) => { |
| 82 | + expect(isObjectSerializable(value)).toBe(true); |
| 83 | + }); |
| 84 | + |
| 85 | + test.each([ |
| 86 | + { description: 'null', value: null }, |
| 87 | + { description: 'undefined', value: undefined }, |
| 88 | + { description: 'a string', value: 'string' }, |
| 89 | + { description: 'a number', value: 123 }, |
| 90 | + { description: 'a boolean', value: true }, |
| 91 | + { description: 'an array', value: [1, 2, 3] }, |
| 92 | + { description: 'a function', value: () => {} }, |
| 93 | + ])('should return false for $description', ({ value }) => { |
| 94 | + expect(isObjectSerializable(value)).toBe(false); |
| 95 | + }); |
| 96 | + |
| 97 | + test('should return false for objects with circular references', () => { |
| 98 | + const circular: Record<string, unknown> = {}; |
| 99 | + circular.self = circular; |
| 100 | + expect(isObjectSerializable(circular)).toBe(false); |
| 101 | + }); |
| 102 | + }); |
61 | 103 | }); |
0 commit comments