How to use the expect.Assertion function in expect

To help you get started, we’ve selected a few expect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github viltgroup / minium / minium-script-js / src / main / resources / modules / minium / expect-webelements.js View on Github external
(function (global, module) {

  var expect = require('expect');
  
  var exports = module.exports;

  /**
   * Exports.
   */

  module.exports = expect;
  
  // let's extend expect.js
  
  expect.Assertion.prototype._assertElements = function (obj, msg, err, expected) {
    obj = obj || this.obj;
    var truth = this.flags.not ? !obj.checkForUnexistence() : obj.checkForExistence();
    this.assert(
      truth, 
      msg || function(){ return 'expected ' + obj + ' to have elements' },
      err || function(){ return 'expected ' + obj + ' to not have elements' },
      expected);
    return this;
  };
  
  expect.Assertion.prototype.elements = function () {
    return this._assertElements(this.obj);
  };
  
  var _expect = function (that, obj) {
    return that.flags.not ? expect(obj).not : expect(obj);
github viltgroup / minium-developer / minium-pupino-common / src / main / resources / modules / expect-webelements.js View on Github external
(function (global, module) {

  var expect = require('expect');
  
  var exports = module.exports;

  /**
   * Exports.
   */

  module.exports = expect;
  
  // let's extend expect.js
  
  expect.Assertion.prototype._assertElements = function (obj, msg, err, expected) {
    obj = obj || this.obj;
    var truth = this.flags.not ? !obj.checkForUnexistence() : obj.checkForExistence();
    this.assert(
      truth, 
      msg || function(){ return 'expected ' + obj + ' to have elements' },
      err || function(){ return 'expected ' + obj + ' to not have elements' },
      expected);
    return this;
  };
  
  expect.Assertion.prototype.elements = function () {
    return this._assertElements(this.obj);
  };
  
  var _expect = function (that, obj) {
    return that.flags.not ? expect(obj).not : expect(obj);
github viltgroup / minium-developer / minium-pupino-common / src / main / resources / modules / expect-webelements.js View on Github external
expect.Assertion.prototype.size = function (n) {
    return this._assertElements(this.obj.applyWebElements(function (n) { return $(this).length == n ? $(':root') : $() }, [ n ]),
      function(){ return 'expected ' + this.obj + ' to have size ' + n + ' but got ' + this.obj.size() },
      function(){ return 'expected ' + this.obj + ' to not have size ' + n }
    );
  };
  
  expect.Assertion.prototype.val = function (expected) {
    return this._assertElements(this.obj.withValue(expected),
      function(){ return 'expected ' + this.obj + ' to have val ' + expected + '" but got ' + this.obj.val() + '"' },
      function(){ return 'expected ' + this.obj + ' to not have val' + expected + '"' }
    );
  };

  expect.Assertion.prototype.attr = function (name, expected) {
    return this._assertElements(this.obj.withAttr(name, expected),
        function(){ return 'expected ' + this.obj + ' to have attr ' + name + '="' + expected + '" but got ' + name + '="' + this.obj.attr(name) + '"' },
        function(){ return 'expected ' + this.obj + ' to not have attr ' + name + '="' + expected + '"' }
    );
  };

  expect.Assertion.prototype.css = function (name, expected) {
    return this._assertElements(this.obj.withCss(name, expected),
      function(){ return 'expected ' + this.obj + ' to have css ' + name + '="' + expected + '" but got ' + name + '="' + this.obj.css(name) + '"' },
      function(){ return 'expected ' + this.obj + ' to not have css ' + name + '="' + expected + '"' }
    );
  };
  
  expect.Assertion.prototype.text = function (expected) {
    return this._assertElements(this.obj.withText(expected),
      function(){ return 'expected ' + this.obj + ' to have text "' + expected + '" but got "' + this.obj.text() + '"' },
github viltgroup / minium / minium-script-js / src / main / resources / modules / minium / expect-webelements.js View on Github external
expect.Assertion.prototype.css = function (name, expected) {
    return this._assertElements(this.obj.withCss(name, expected),
      function(){ return 'expected ' + this.obj + ' to have css ' + name + '="' + expected + '" but got ' + name + '="' + this.obj.css(name) + '"' },
      function(){ return 'expected ' + this.obj + ' to not have css ' + name + '="' + expected + '"' }
    );
  };
  
  expect.Assertion.prototype.text = function (expected) {
    return this._assertElements(this.obj.withText(expected),
      function(){ return 'expected ' + this.obj + ' to have text "' + expected + '" but got "' + this.obj.text() + '"' },
      function(){ return 'expected ' + this.obj + ' to not have text "' + expected + '"' }
    );
  };
  
  expect.Assertion.prototype.exist = function (expected) {
    var truth = this.flags.not ? !this.obj.checkForUnexistence() : this.obj.checkForExistence();
    this.assert(
        truth
      , function(){ return 'expected ' + this.obj + ' to exist' }
      , function(){ return 'expected ' + this.obj + ' not to exist' });
    return this;
  };
  
})(this, 'undefined' != typeof module ? module : {exports: {}});

expect

This package exports the `expect` function used in [Jest](https://jestjs.io/). You can find its documentation [on Jest's website](https://jestjs.io/docs/expect).

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis