]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/assertions.js
1 // Assertions that make it easier to use sinon
2 import sinonChai
from '../node_modules/sinon-chai/lib/sinon-chai.js';
5 // noVNC specific assertions
6 chai
.use(function (_chai
, utils
) {
7 _chai
.Assertion
.addMethod('displayed', function (target_data
) {
9 var ctx
= obj
._target
.getContext('2d');
10 var data_cl
= ctx
.getImageData(0, 0, obj
._target
.width
, obj
._target
.height
).data
;
11 // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
12 var data
= new Uint8Array(data_cl
);
14 var len
= data_cl
.length
;
15 if (len
!= target_data
.length
) {
18 for (var i
= 0; i
< len
; i
++) {
19 if (data
[i
] != target_data
[i
]) {
26 console
.log("expected data: %o, actual data: %o", target_data
, data
);
29 "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
30 "expected #{this} not to have displayed the image #{act}",
35 _chai
.Assertion
.addMethod('sent', function (target_data
) {
37 obj
.inspect = function () {
38 var res
= { _websocket
: obj
._websocket
, rQi
: obj
._rQi
, _rQ
: new Uint8Array(obj
._rQ
.buffer
, 0, obj
._rQlen
),
39 _sQ
: new Uint8Array(obj
._sQ
.buffer
, 0, obj
._sQlen
) };
43 var data
= obj
._websocket
._get_sent_data();
45 if (data
.length
!= target_data
.length
) {
48 for (var i
= 0; i
< data
.length
; i
++) {
49 if (data
[i
] != target_data
[i
]) {
56 console
.log("expected data: %o, actual data: %o", target_data
, data
);
59 "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
60 "expected #{this} not to have sent the data #{act}",
61 Array
.prototype.slice
.call(target_data
),
62 Array
.prototype.slice
.call(data
));
65 _chai
.Assertion
.addProperty('array', function () {
66 utils
.flag(this, 'array', true);
69 _chai
.Assertion
.overwriteMethod('equal', function (_super
) {
70 return function assertArrayEqual(target
) {
71 if (utils
.flag(this, 'array')) {
77 if (utils
.flag(this, 'deep')) {
78 for (i
= 0; i
< obj
.length
; i
++) {
79 if (!utils
.eql(obj
[i
], target
[i
])) {
86 "expected #{this} to have elements deeply equal to #{exp}",
87 "expected #{this} not to have elements deeply equal to #{exp}",
88 Array
.prototype.slice
.call(target
));
90 for (i
= 0; i
< obj
.length
; i
++) {
91 if (obj
[i
] != target
[i
]) {
98 "expected #{this} to have elements equal to #{exp}",
99 "expected #{this} not to have elements equal to #{exp}",
100 Array
.prototype.slice
.call(target
));
103 _super
.apply(this, arguments
);