[gjs: 4/5] print: Define API writable
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 4/5] print: Define API writable
- Date: Thu, 3 Sep 2020 21:04:25 +0000 (UTC)
commit 1677770ca6b01be3ace0e3f31b10cb8eb50b4263
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Aug 30 16:54:06 2020 -0700
print: Define API writable
In order to match the GJS_MODULE_PROP_FLAGS that they were previously
defined with before the split into a separate module, the print
functions need to be defined with writable: true on the global object.
Without this, `spyOn(globalThis, 'print')` will not work.
installed-tests/js/meson.build | 1 +
installed-tests/js/testPrint.js | 31 +++++++++++++++++++++++++++++++
modules/script/_bootstrap/default.js | 4 ++++
3 files changed, 36 insertions(+)
---
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index a9c030b98..b6fa7ce3e 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -109,6 +109,7 @@ jasmine_tests = [
'Namespace',
'Package',
'ParamSpec',
+ 'Print',
'Regress',
'Signals',
'System',
diff --git a/installed-tests/js/testPrint.js b/installed-tests/js/testPrint.js
new file mode 100644
index 000000000..c42b0003d
--- /dev/null
+++ b/installed-tests/js/testPrint.js
@@ -0,0 +1,31 @@
+describe('print', function () {
+ it('can be spied upon', function () {
+ spyOn(globalThis, 'print');
+ print('foo');
+ expect(print).toHaveBeenCalledWith('foo');
+ });
+});
+
+describe('printerr', function () {
+ it('can be spied upon', function () {
+ spyOn(globalThis, 'printerr');
+ printerr('foo');
+ expect(printerr).toHaveBeenCalledWith('foo');
+ });
+});
+
+describe('log', function () {
+ it('can be spied upon', function () {
+ spyOn(globalThis, 'log');
+ log('foo');
+ expect(log).toHaveBeenCalledWith('foo');
+ });
+});
+
+describe('logError', function () {
+ it('can be spied upon', function () {
+ spyOn(globalThis, 'logError');
+ logError('foo', 'bar');
+ expect(logError).toHaveBeenCalledWith('foo', 'bar');
+ });
+});
diff --git a/modules/script/_bootstrap/default.js b/modules/script/_bootstrap/default.js
index 6b2200960..4c1fb1791 100644
--- a/modules/script/_bootstrap/default.js
+++ b/modules/script/_bootstrap/default.js
@@ -7,21 +7,25 @@
print: {
configurable: false,
enumerable: true,
+ writable: true,
value: print,
},
printerr: {
configurable: false,
enumerable: true,
+ writable: true,
value: printerr,
},
log: {
configurable: false,
enumerable: true,
+ writable: true,
value: log,
},
logError: {
configurable: false,
enumerable: true,
+ writable: true,
value: logError,
},
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]