1 | import ExpoRandom from '../ExpoRandom';
|
2 | import * as Random from '../Random';
|
3 |
|
4 | it(`invokes native method correctly`, async () => {
|
5 | ExpoRandom.getRandomBase64StringAsync.mockImplementationOnce(async () => '');
|
6 | const value = await Random.getRandomBytesAsync(0);
|
7 | expect(value instanceof Uint8Array).toBe(true);
|
8 | expect(ExpoRandom.getRandomBase64StringAsync).toHaveBeenLastCalledWith(0);
|
9 | });
|
10 |
|
11 | it(`returns an array with the desired number of bytes`, async () => {
|
12 | ExpoRandom.getRandomBase64StringAsync.mockImplementationOnce(async () => 'r6ip');
|
13 | const value = await Random.getRandomBytesAsync(3);
|
14 | expect(value.length).toBe(3);
|
15 | });
|
16 |
|
17 | it(`asserts invalid byte count errors`, async () => {
|
18 | await expect(Random.getRandomBytesAsync(-1)).rejects.toThrowError(TypeError);
|
19 | await expect(Random.getRandomBytesAsync(1025)).rejects.toThrowError(TypeError);
|
20 | await expect(Random.getRandomBytesAsync('invalid' as any)).rejects.toThrowError(TypeError);
|
21 | await expect(Random.getRandomBytesAsync(null as any)).rejects.toThrowError(TypeError);
|
22 | await expect(Random.getRandomBytesAsync({} as any)).rejects.toThrowError(TypeError);
|
23 | await expect(Random.getRandomBytesAsync(NaN)).rejects.toThrowError(TypeError);
|
24 | });
|
25 |
|
26 | it(`accepts valid byte counts`, async () => {
|
27 | await expect(Random.getRandomBytesAsync(0));
|
28 | await expect(Random.getRandomBytesAsync(1024));
|
29 | await expect(Random.getRandomBytesAsync(512.5));
|
30 | });
|