2019-10-24 15:54:32 +02:00
|
|
|
|
|
|
|
/* eslint-disable no-native-reassign */
|
|
|
|
|
|
|
|
// this is what we're testing
|
2020-01-09 04:34:58 +01:00
|
|
|
import '../../app/scripts/lib/freezeGlobals'
|
2019-10-24 15:54:32 +02:00
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
import assert from 'assert'
|
2019-10-24 15:54:32 +02:00
|
|
|
|
|
|
|
describe('Promise global is immutable', () => {
|
|
|
|
|
|
|
|
it('throws when reassinging promise (syntax 1)', () => {
|
|
|
|
try {
|
|
|
|
Promise = {}
|
|
|
|
assert.fail('did not throw error')
|
|
|
|
} catch (err) {
|
|
|
|
assert.ok(err, 'did throw error')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws when reassinging promise (syntax 2)', () => {
|
|
|
|
try {
|
|
|
|
global.Promise = {}
|
|
|
|
assert.fail('did not throw error')
|
|
|
|
} catch (err) {
|
|
|
|
assert.ok(err, 'did throw error')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws when mutating existing Promise property', () => {
|
|
|
|
try {
|
|
|
|
Promise.all = () => {}
|
|
|
|
assert.fail('did not throw error')
|
|
|
|
} catch (err) {
|
|
|
|
assert.ok(err, 'did throw error')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws when adding new Promise property', () => {
|
|
|
|
try {
|
|
|
|
Promise.foo = 'bar'
|
|
|
|
assert.fail('did not throw error')
|
|
|
|
} catch (err) {
|
|
|
|
assert.ok(err, 'did throw error')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws when deleting Promise from global', () => {
|
|
|
|
try {
|
|
|
|
delete global.Promise
|
|
|
|
assert.fail('did not throw error')
|
|
|
|
} catch (err) {
|
|
|
|
assert.ok(err, 'did throw error')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|