assertions.js 1.1 KB

123456789101112131415161718192021222324
  1. // some useful assertions for noVNC
  2. chai.use(function (_chai, utils) {
  3. _chai.Assertion.addMethod('displayed', function (target_data) {
  4. var obj = this._obj;
  5. var data_cl = obj._drawCtx.getImageData(0, 0, obj._viewportLoc.w, obj._viewportLoc.h).data;
  6. // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
  7. var data = new Uint8Array(data_cl);
  8. this.assert(utils.eql(data, target_data),
  9. "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
  10. "expected #{this} not to have displayed the image #{act}",
  11. target_data,
  12. data);
  13. });
  14. _chai.Assertion.addMethod('sent', function (target_data) {
  15. var obj = this._obj;
  16. var data = obj._websocket._get_sent_data();
  17. this.assert(utils.eql(data, target_data),
  18. "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
  19. "expected #{this} not to have sent the data #{act}",
  20. target_data,
  21. data);
  22. });
  23. });