]>
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
);
13 var len
= data_cl
.length
;
14 new chai
.Assertion(len
).to
.be
.equal(target_data
.length
, "unexpected display size");
16 for (var i
= 0; i
< len
; i
++) {
17 if (data
[i
] != target_data
[i
]) {
23 console
.log("expected data: %o, actual data: %o", target_data
, data
);
26 "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
27 "expected #{this} not to have displayed the image #{act}",
32 _chai
.Assertion
.addMethod('sent', function (target_data
) {
34 obj
.inspect = function () {
35 var res
= { _websocket
: obj
._websocket
, rQi
: obj
._rQi
, _rQ
: new Uint8Array(obj
._rQ
.buffer
, 0, obj
._rQlen
),
36 _sQ
: new Uint8Array(obj
._sQ
.buffer
, 0, obj
._sQlen
) };
40 var data
= obj
._websocket
._get_sent_data();
42 if (data
.length
!= target_data
.length
) {
45 for (var i
= 0; i
< data
.length
; i
++) {
46 if (data
[i
] != target_data
[i
]) {
53 console
.log("expected data: %o, actual data: %o", target_data
, data
);
56 "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
57 "expected #{this} not to have sent the data #{act}",
58 Array
.prototype.slice
.call(target_data
),
59 Array
.prototype.slice
.call(data
));
62 _chai
.Assertion
.addProperty('array', function () {
63 utils
.flag(this, 'array', true);
66 _chai
.Assertion
.overwriteMethod('equal', function (_super
) {
67 return function assertArrayEqual(target
) {
68 if (utils
.flag(this, 'array')) {
74 if (utils
.flag(this, 'deep')) {
75 for (i
= 0; i
< obj
.length
; i
++) {
76 if (!utils
.eql(obj
[i
], target
[i
])) {
83 "expected #{this} to have elements deeply equal to #{exp}",
84 "expected #{this} not to have elements deeply equal to #{exp}",
85 Array
.prototype.slice
.call(target
));
87 for (i
= 0; i
< obj
.length
; i
++) {
88 if (obj
[i
] != target
[i
]) {
95 "expected #{this} to have elements equal to #{exp}",
96 "expected #{this} not to have elements equal to #{exp}",
97 Array
.prototype.slice
.call(target
));
100 _super
.apply(this, arguments
);