(
options: SetupCryptoMocksOptions = {},
)
| 115 | * ``` |
| 116 | */ |
| 117 | export function setupCryptoMocks( |
| 118 | options: SetupCryptoMocksOptions = {}, |
| 119 | ): CryptoMockSpies { |
| 120 | const { prefix = 'mock-uuid', sequential = false, uuids = [] } = options |
| 121 | |
| 122 | let callCount = 0 |
| 123 | |
| 124 | const randomUUIDSpy = spyOn(crypto, 'randomUUID').mockImplementation(() => { |
| 125 | const currentIndex = callCount |
| 126 | callCount++ |
| 127 | |
| 128 | // First try to return from the provided list |
| 129 | if (currentIndex < uuids.length) { |
| 130 | return uuids[currentIndex] |
| 131 | } |
| 132 | |
| 133 | // Then fall back to generated UUIDs |
| 134 | if (sequential) { |
| 135 | return createMockUuid(prefix, currentIndex) |
| 136 | } |
| 137 | |
| 138 | return createMockUuid(prefix) |
| 139 | }) |
| 140 | |
| 141 | return { |
| 142 | randomUUID: randomUUIDSpy, |
| 143 | restore: () => { |
| 144 | randomUUIDSpy.mockRestore() |
| 145 | }, |
| 146 | clear: () => { |
| 147 | callCount = 0 |
| 148 | randomUUIDSpy.mockClear() |
| 149 | }, |
| 150 | getCallCount: () => callCount, |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Sets up crypto mocks that return specific UUIDs in sequence. |
no test coverage detected