1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2020 Philip Chimento <philip.chimento@gmail.com>
// SPDX-FileCopyrightText: 2022 Nasah Kuma <nasahnash19@gmail.com>
const GLib = imports.gi.GLib;
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');
});
});
describe('prettyPrint', function () {
afterEach(function () {
GLib.test_assert_expected_messages_internal('Gjs', 'testPrint.js', 0,
'pretty print');
});
it('property value primitive', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: { greeting: "hi" }');
log({greeting: 'hi'});
});
it('more than one property', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: { a: 1, b: 2, c: 3 }');
log({a: 1, b: 2, c: 3});
});
it('array', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: [1, 2, 3, 4, 5]');
log([1, 2, 3, 4, 5]);
});
it('property value array', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: { arr: [1, 2, 3, 4, 5] }');
log({arr: [1, 2, 3, 4, 5]});
});
it('nested array', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: [1, 2, [3, 4], 5]');
log([1, 2, [3, 4], 5]);
});
it('property value nested array', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: { arr: [1, 2, [3, 4], 5] }');
log({arr: [1, 2, [3, 4], 5]});
});
it('function', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: [ Function: sum ]');
log(function sum(a, b) {
return a + b;
});
});
it('property value function', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: { sum: [ Function: sum ] }');
log({
sum: function sum(a, b) {
return a + b;
},
});
});
it('date', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: 2018-12-24T10:33:30.000Z');
log(new Date(Date.UTC(2018, 11, 24, 10, 33, 30)));
});
it('property value date', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_MESSAGE,
'JS LOG: { date: 2018-12-24T10:33:30.000Z }');
log({date: new Date(Date.UTC(2018, 11, 24, 10, 33, 30))});
});
});
|