]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/assertions.js
1 // noVNC specific assertions
2 chai
.use(function (_chai
, utils
) {
3 function _equal(a
, b
) {
6 _chai
.Assertion
.addMethod('displayed', function (targetData
, cmp
=_equal
) {
8 const ctx
= obj
._target
.getContext('2d');
9 const data
= ctx
.getImageData(0, 0, obj
._target
.width
, obj
._target
.height
).data
;
10 const len
= data
.length
;
11 new chai
.Assertion(len
).to
.be
.equal(targetData
.length
, "unexpected display size");
13 for (let i
= 0; i
< len
; i
++) {
14 if (!cmp(data
[i
], targetData
[i
])) {
20 // eslint-disable-next-line no-console
21 console
.log("expected data: %o, actual data: %o", targetData
, data
);
24 "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
25 "expected #{this} not to have displayed the image #{act}",
30 _chai
.Assertion
.addMethod('sent', function (targetData
) {
31 const obj
= this._obj
;
33 const res
= { _websocket
: obj
._websocket
, rQi
: obj
._rQi
, _rQ
: new Uint8Array(obj
._rQ
.buffer
, 0, obj
._rQlen
),
34 _sQ
: new Uint8Array(obj
._sQ
.buffer
, 0, obj
._sQlen
) };
38 const data
= obj
._websocket
._getSentData();
40 if (data
.length
!= targetData
.length
) {
43 for (let i
= 0; i
< data
.length
; i
++) {
44 if (data
[i
] != targetData
[i
]) {
51 // eslint-disable-next-line no-console
52 console
.log("expected data: %o, actual data: %o", targetData
, data
);
55 "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
56 "expected #{this} not to have sent the data #{act}",
57 Array
.prototype.slice
.call(targetData
),
58 Array
.prototype.slice
.call(data
));
61 _chai
.Assertion
.addProperty('array', function () {
62 utils
.flag(this, 'array', true);
65 _chai
.Assertion
.overwriteMethod('equal', function (_super
) {
66 return function assertArrayEqual(target
) {
67 if (utils
.flag(this, 'array')) {
68 const obj
= this._obj
;
72 if (utils
.flag(this, 'deep')) {
73 for (let i
= 0; i
< obj
.length
; i
++) {
74 if (!utils
.eql(obj
[i
], target
[i
])) {
81 "expected #{this} to have elements deeply equal to #{exp}",
82 "expected #{this} not to have elements deeply equal to #{exp}",
83 Array
.prototype.slice
.call(target
));
85 for (let i
= 0; i
< obj
.length
; i
++) {
86 if (obj
[i
] != target
[i
]) {
93 "expected #{this} to have elements equal to #{exp}",
94 "expected #{this} not to have elements equal to #{exp}",
95 Array
.prototype.slice
.call(target
));
98 _super
.apply(this, arguments
);