Skip to content

Commit 3b790fa

Browse files
committed
specs: skip or conditionally spy on console.error when it's not spyable
GJS defines console.error as a non-writable, non-configurable property. SpyRegistry checks the property descriptor and throws: Error: <spyOn> : error is not declared writable or has no setter Add guards to skip or conditionally execute tests that spy on console.error when the property is not spyable. This affects: - DeprecatorSpec: skip all #deprecate tests via beforeEach - DeprecationSpec: skip all integration tests via beforeEach - EnvSpec: skip the deprecation stack test - baseSpec: conditionally spy on console.error in the setTimeout test
1 parent daf83bb commit 3b790fa

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

spec/core/DeprecatorSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
describe('Deprecator', function() {
33
describe('#deprecate', function() {
44
beforeEach(function() {
5+
const descriptor = Object.getOwnPropertyDescriptor(console, 'error');
6+
if (descriptor && !(descriptor.writable || descriptor.set)) {
7+
pending('console.error is not spyable in this environment');
8+
return;
9+
}
10+
511
spyOn(console, 'error');
612
});
713

spec/core/baseSpec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,18 @@ describe('base helpers', function() {
160160
if (typeof process !== 'undefined' && process.emitWarning) {
161161
spyOn(process, 'emitWarning'); // Node 22
162162
}
163-
spyOn(console, 'error'); // Node <22
163+
164+
const consoleErrorDescriptor = Object.getOwnPropertyDescriptor(
165+
console,
166+
'error'
167+
);
168+
if (
169+
!consoleErrorDescriptor ||
170+
consoleErrorDescriptor.writable ||
171+
consoleErrorDescriptor.set
172+
) {
173+
spyOn(console, 'error'); // Node <22
174+
}
164175

165176
let id = setTimeout(f1, max);
166177
setTimeout(function() {

spec/core/integration/DeprecationSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
describe('Deprecation (integration)', function() {
33
let env;
44

5+
function consoleErrorIsSpyable() {
6+
const descriptor = Object.getOwnPropertyDescriptor(console, 'error');
7+
return !descriptor || descriptor.writable || descriptor.set;
8+
}
9+
510
beforeEach(function() {
11+
if (!consoleErrorIsSpyable()) {
12+
pending('console.error is not spyable in this environment');
13+
return;
14+
}
15+
616
env = new privateUnderTest.Env();
717
});
818

spec/core/integration/EnvSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,6 +2945,12 @@ describe('Env integration', function() {
29452945
});
29462946

29472947
it('should report deprecation stack with an error object', async function() {
2948+
const descriptor = Object.getOwnPropertyDescriptor(console, 'error');
2949+
if (descriptor && !(descriptor.writable || descriptor.set)) {
2950+
pending('console.error is not spyable in this environment');
2951+
return;
2952+
}
2953+
29482954
const exceptionFormatter = new privateUnderTest.ExceptionFormatter();
29492955
const reporter = jasmine.createSpyObj('reporter', [
29502956
'jasmineDone',

0 commit comments

Comments
 (0)