Best JavaScript code snippet using pact-foundation-pact
numbermatcher.js
Source:numbermatcher.js  
1/**2 * @license3 * Copyright The Closure Library Authors.4 * SPDX-License-Identifier: Apache-2.05 */6/**7 * @fileoverview Provides the built-in number matchers like lessThan,8 * greaterThan, etc.9 */10goog.provide('goog.labs.testing.numbermatcher');11goog.require('goog.asserts');12goog.require('goog.labs.testing.Matcher');13/**14 * Matches any number value.15 *16 * @constructor @struct @implements {goog.labs.testing.Matcher} @final17 */18goog.labs.testing.numbermatcher.AnyNumberMatcher = function() {};19/** @override */20goog.labs.testing.numbermatcher.AnyNumberMatcher.prototype.matches = function(21    actualValue) {22  'use strict';23  return typeof actualValue === 'number';24};25/** @override */26goog.labs.testing.numbermatcher.AnyNumberMatcher.prototype.describe = function(27    actualValue) {28  'use strict';29  return '<' + actualValue + '> is not a number';30};31/**32 * The GreaterThan matcher.33 *34 * @param {number} value The value to compare.35 *36 * @constructor37 * @struct38 * @implements {goog.labs.testing.Matcher}39 * @final40 */41goog.labs.testing.numbermatcher.GreaterThanMatcher = function(value) {42  'use strict';43  /**44   * @type {number}45   * @private46   */47  this.value_ = value;48};49/**50 * Determines if input value is greater than the expected value.51 *52 * @override53 */54goog.labs.testing.numbermatcher.GreaterThanMatcher.prototype.matches = function(55    actualValue) {56  'use strict';57  goog.asserts.assertNumber(actualValue);58  return actualValue > this.value_;59};60/**61 * @override62 */63goog.labs.testing.numbermatcher.GreaterThanMatcher.prototype.describe =64    function(actualValue) {65  'use strict';66  goog.asserts.assertNumber(actualValue);67  return actualValue + ' is not greater than ' + this.value_;68};69/**70 * The lessThan matcher.71 *72 * @param {number} value The value to compare.73 *74 * @constructor75 * @struct76 * @implements {goog.labs.testing.Matcher}77 * @final78 */79goog.labs.testing.numbermatcher.LessThanMatcher = function(value) {80  'use strict';81  /**82   * @type {number}83   * @private84   */85  this.value_ = value;86};87/**88 * Determines if the input value is less than the expected value.89 *90 * @override91 */92goog.labs.testing.numbermatcher.LessThanMatcher.prototype.matches = function(93    actualValue) {94  'use strict';95  goog.asserts.assertNumber(actualValue);96  return actualValue < this.value_;97};98/**99 * @override100 */101goog.labs.testing.numbermatcher.LessThanMatcher.prototype.describe = function(102    actualValue) {103  'use strict';104  goog.asserts.assertNumber(actualValue);105  return actualValue + ' is not less than ' + this.value_;106};107/**108 * The GreaterThanEqualTo matcher.109 *110 * @param {number} value The value to compare.111 *112 * @constructor113 * @struct114 * @implements {goog.labs.testing.Matcher}115 * @final116 */117goog.labs.testing.numbermatcher.GreaterThanEqualToMatcher = function(value) {118  'use strict';119  /**120   * @type {number}121   * @private122   */123  this.value_ = value;124};125/**126 * Determines if the input value is greater than equal to the expected value.127 *128 * @override129 */130goog.labs.testing.numbermatcher.GreaterThanEqualToMatcher.prototype.matches =131    function(actualValue) {132  'use strict';133  goog.asserts.assertNumber(actualValue);134  return actualValue >= this.value_;135};136/**137 * @override138 */139goog.labs.testing.numbermatcher.GreaterThanEqualToMatcher.prototype.describe =140    function(actualValue) {141  'use strict';142  goog.asserts.assertNumber(actualValue);143  return actualValue + ' is not greater than equal to ' + this.value_;144};145/**146 * The LessThanEqualTo matcher.147 *148 * @param {number} value The value to compare.149 *150 * @constructor151 * @struct152 * @implements {goog.labs.testing.Matcher}153 * @final154 */155goog.labs.testing.numbermatcher.LessThanEqualToMatcher = function(value) {156  'use strict';157  /**158   * @type {number}159   * @private160   */161  this.value_ = value;162};163/**164 * Determines if the input value is less than or equal to the expected value.165 *166 * @override167 */168goog.labs.testing.numbermatcher.LessThanEqualToMatcher.prototype.matches =169    function(actualValue) {170  'use strict';171  goog.asserts.assertNumber(actualValue);172  return actualValue <= this.value_;173};174/**175 * @override176 */177goog.labs.testing.numbermatcher.LessThanEqualToMatcher.prototype.describe =178    function(actualValue) {179  'use strict';180  goog.asserts.assertNumber(actualValue);181  return actualValue + ' is not less than equal to ' + this.value_;182};183/**184 * The EqualTo matcher.185 *186 * @param {number} value The value to compare.187 *188 * @constructor189 * @struct190 * @implements {goog.labs.testing.Matcher}191 * @final192 */193goog.labs.testing.numbermatcher.EqualToMatcher = function(value) {194  'use strict';195  /**196   * @type {number}197   * @private198   */199  this.value_ = value;200};201/**202 * Determines if the input value is equal to the expected value.203 *204 * @override205 */206goog.labs.testing.numbermatcher.EqualToMatcher.prototype.matches = function(207    actualValue) {208  'use strict';209  goog.asserts.assertNumber(actualValue);210  return actualValue === this.value_;211};212/**213 * @override214 */215goog.labs.testing.numbermatcher.EqualToMatcher.prototype.describe = function(216    actualValue) {217  'use strict';218  goog.asserts.assertNumber(actualValue);219  return actualValue + ' is not equal to ' + this.value_;220};221/**222 * The CloseTo matcher.223 *224 * @param {number} value The value to compare.225 * @param {number} range The range to check within.226 *227 * @constructor228 * @struct229 * @implements {goog.labs.testing.Matcher}230 * @final231 */232goog.labs.testing.numbermatcher.CloseToMatcher = function(value, range) {233  'use strict';234  /**235   * @type {number}236   * @private237   */238  this.value_ = value;239  /**240   * @type {number}241   * @private242   */243  this.range_ = range;244};245/**246 * Determines if input value is within a certain range of the expected value.247 *248 * @override249 */250goog.labs.testing.numbermatcher.CloseToMatcher.prototype.matches = function(251    actualValue) {252  'use strict';253  goog.asserts.assertNumber(actualValue);254  return Math.abs(this.value_ - actualValue) < this.range_;255};256/**257 * @override258 */259goog.labs.testing.numbermatcher.CloseToMatcher.prototype.describe = function(260    actualValue) {261  'use strict';262  goog.asserts.assertNumber(actualValue);263  return actualValue + ' is not close to(' + this.range_ + ') ' + this.value_;264};265/** @return {!goog.labs.testing.numbermatcher.AnyNumberMatcher} */266goog.labs.testing.numbermatcher.AnyNumberMatcher.anyNumber = function() {267  'use strict';268  return new goog.labs.testing.numbermatcher.AnyNumberMatcher();269};270/**271 * @param {number} value The expected value.272 *273 * @return {!goog.labs.testing.numbermatcher.GreaterThanMatcher} A274 *     GreaterThanMatcher.275 */276goog.labs.testing.numbermatcher.GreaterThanMatcher.greaterThan = function(277    value) {278  'use strict';279  return new goog.labs.testing.numbermatcher.GreaterThanMatcher(value);280};281/**282 * @param {number} value The expected value.283 *284 * @return {!goog.labs.testing.numbermatcher.GreaterThanEqualToMatcher} A285 *     GreaterThanEqualToMatcher.286 */287goog.labs.testing.numbermatcher.GreaterThanEqualToMatcher.greaterThanEqualTo =288    function(value) {289  'use strict';290  return new goog.labs.testing.numbermatcher.GreaterThanEqualToMatcher(value);291};292/**293 * @param {number} value The expected value.294 *295 * @return {!goog.labs.testing.numbermatcher.LessThanMatcher} A LessThanMatcher.296 */297goog.labs.testing.numbermatcher.LessThanMatcher.lessThan = function(value) {298  'use strict';299  return new goog.labs.testing.numbermatcher.LessThanMatcher(value);300};301/**302 * @param {number} value The expected value.303 *304 * @return {!goog.labs.testing.numbermatcher.LessThanEqualToMatcher} A305 *     LessThanEqualToMatcher.306 */307goog.labs.testing.numbermatcher.LessThanEqualToMatcher.lessThanEqualTo =308    function(value) {309  'use strict';310  return new goog.labs.testing.numbermatcher.LessThanEqualToMatcher(value);311};312/**313 * @param {number} value The expected value.314 *315 * @return {!goog.labs.testing.numbermatcher.EqualToMatcher} An EqualToMatcher.316 */317goog.labs.testing.numbermatcher.EqualToMatcher.equalTo = function(value) {318  'use strict';319  return new goog.labs.testing.numbermatcher.EqualToMatcher(value);320};321/**322 * @param {number} value The expected value.323 * @param {number} range The maximum allowed difference from the expected value.324 *325 * @return {!goog.labs.testing.numbermatcher.CloseToMatcher} A CloseToMatcher.326 */327goog.labs.testing.numbermatcher.CloseToMatcher.closeTo = function(328    value, range) {329  'use strict';330  return new goog.labs.testing.numbermatcher.CloseToMatcher(value, range);...Using AI Code Generation
1const { Matchers } = require('@pact-foundation/pact');2const { somethingLike } = Matchers;3const body = {4  number: somethingLike(123),5};6module.exports = body;7const { Matchers } = require('@pact-foundation/pact');8const { somethingLike } = Matchers;9const body = {10  number: somethingLike(123),11};12module.exports = body;13const { Matchers } = require('@pact-foundation/pact');14const { somethingLike } = Matchers;15const body = {16  number: somethingLike(123),17};18module.exports = body;19const { Matchers } = require('@pact-foundation/pact');20const { somethingLike } = Matchers;21const body = {22  number: somethingLike(123),23};24module.exports = body;25const { Matchers } = require('@pact-foundation/pact');26const { somethingLike } = Matchers;27const body = {28  number: somethingLike(123),29};30module.exports = body;31const { Matchers } = require('@pact-foundation/pact');32const { somethingLike } = Matchers;33const body = {34  number: somethingLike(123),35};36module.exports = body;37const { Matchers } = require('@pact-foundation/pact');38const { somethingLike } = Matchers;39const body = {40  number: somethingLike(123),41};42module.exports = body;43const { Matchers } = require('@pact-foundation/pact');44const { somethingLike } = Matchers;45const body = {46  number: somethingLike(123),47};48module.exports = body;49const { Matchers } = require('@pact-fUsing AI Code Generation
1var numberMatcher = require('pact-foundation-pact').numberMatcher;2var something = numberMatcher(12345);3var something = require('./test2.js').something;4var somethingElse = 12345;5expect(something).toEqual(somethingElse);6expect(something).toEqual(numberMatcher(somethingElse));Using AI Code Generation
1const pact = require('pact-foundation/pact');2const { numberMatcher } = pact.Matchers;3const matcher = numberMatcher(10);4console.log(matcher);5{6  data: { generate: '10', matcher: { json_class: 'Regexp', o: 0, s: '10' } }7}8const pact = require('pact-foundation/pact');9const { like } = pact.Matchers;10const matcher = like('10');11console.log(matcher);12{13}14const pact = require('pact-foundation/pact');15const { eachLike } = pact.Matchers;16const matcher = eachLike('10');17console.log(matcher);18{19}20const pact = require('pact-foundation/pact');21const { term } = pact.Matchers;22const matcher = term({23});24console.log(matcher);25{26  data: { generate: '10', matcher: { json_class: 'Regexp', o: 0, s: '10' } }27}28const pact = require('pact-foundation/pact');29const { somethingLike } = pact.Matchers;30const matcher = somethingLike('10');31console.log(matcher);32{33}34const pact = require('pact-foundation/pact');35const { arrayLike } = pact.Matchers;36const matcher = arrayLike('10');37console.log(matcher);38{Using AI Code Generation
1const numberMatcher = require('pact-foundation-pact').Matchers.numberMatcher;2const number = 123;3const numberMatcher = numberMatcher(number);4const term = require('pact-foundation-pact').Matchers.term;5const term = term({6});7const eachLike = require('pact-foundation-pact').Matchers.eachLike;8const eachLike = eachLike('123', {min: 1});9const like = require('pact-foundation-pact').Matchers.like;10const like = like('123');11const somethingLike = require('pact-foundation-pact').Matchers.somethingLike;12const somethingLike = somethingLike('123');13const numberMatcher = require('pact-foundation-pact').Matchers.numberMatcher;14const number = 123;15const numberMatcher = numberMatcher(number);Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
