Skip to content

Commit

Permalink
Another way to clean after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Dec 8, 2022
1 parent 264c25b commit a8592e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
20 changes: 13 additions & 7 deletions test/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import { urlAlphabet } from '../index.js'
import * as browser from '../async/index.browser.js'
import * as node from '../async/index.js'

Object.defineProperty(global, 'crypto', {
value: {
getRandomValues(array) {
for (let i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * 256)
test.before(() => {
Object.defineProperty(global, 'crypto', {
value: {
getRandomValues(array) {
for (let i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * 256)
}
return array
}
return array
}
}
})
})

test.after(() => {
Object.defineProperty(global, 'crypto', { value: undefined })
})

function times(size, callback) {
Expand Down
3 changes: 1 addition & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as node from '../index.js'

test.before(() => {
Object.defineProperty(global, 'crypto', {
configurable: true,
value: {
getRandomValues(array) {
for (let i = 0; i < array.length; i++) {
Expand All @@ -19,7 +18,7 @@ test.before(() => {
})

test.after(() => {
delete global.crypto
Object.defineProperty(global, 'crypto', { value: undefined })
})

for (let type of ['node', 'browser']) {
Expand Down
2 changes: 1 addition & 1 deletion test/react-native-polyfill.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.before(() => {

test.after(() => {
delete global.navigator
delete global.crypto
Object.defineProperty(global, 'crypto', { value: undefined })
})

test('works with polyfill', () => {
Expand Down

0 comments on commit a8592e5

Please sign in to comment.