Skip to content

Commit dec66f9

Browse files
Reverted the test updates and added new jest env hint.
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
1 parent fe77ca3 commit dec66f9

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/WebGenerator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Generator from './Generator';
33
export default class WebGenerator extends Generator {
44
getRandom (len) {
55
const list = new Uint8Array(len);
6-
if ((global || window).crypto) {
7-
(global || window).crypto.getRandomValues(list);
6+
if (window.crypto) {
7+
window.crypto.getRandomValues(list);
88
return list;
99
}
1010

test/WebGenerator.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
14
import WebGenerator from '../src/WebGenerator';
25

36
const generator = new WebGenerator();
@@ -34,11 +37,11 @@ describe('Tests for web generator.', () => {
3437
});
3538

3639
test('Uses crypt of it exists.', () => {
37-
Object.defineProperty(global, 'crypto', {
38-
value: {
39-
getRandomValues: (a) => a.fill(1).values()
40+
window.crypto = {
41+
getRandomValues (array) {
42+
array = array.fill(1).values();
4043
}
41-
});
44+
};
4245

4346
const result = generator.getRandom(10);
4447
expect(result).toEqual(Uint8Array.from([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]));

0 commit comments

Comments
 (0)