@locustjs/test 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -528,6 +528,40 @@ class Expect {
528
528
  }
529
529
  return this;
530
530
  }
531
+ toBeValid(fnValidation) {
532
+ if (!isFunction(fnValidation)) {
533
+ throw new Exception({
534
+ message: `fnValidation is not function`,
535
+ code: 1064,
536
+ status: 'to-be-valid'
537
+ });
538
+ }
539
+ if (!fnValidation(this.value)) {
540
+ throw new Exception({
541
+ message: `${this.value} is not valid`,
542
+ code: 1065,
543
+ status: 'to-be-valid'
544
+ });
545
+ }
546
+ return this;
547
+ }
548
+ notToBeValid(fnValidation) {
549
+ if (!isFunction(fnValidation)) {
550
+ throw new Exception({
551
+ message: `fnValidation is not function`,
552
+ code: 1066,
553
+ status: 'not-to-be-valid'
554
+ });
555
+ }
556
+ if (fnValidation(this.value)) {
557
+ throw new Exception({
558
+ message: `${this.value} is valid`,
559
+ code: 1067,
560
+ status: 'not-to-be-valid'
561
+ });
562
+ }
563
+ return this;
564
+ }
531
565
  toThrow(ex, shape = false, strict = false) {
532
566
  if (!isFunction(this.value)) {
533
567
  throw new Exception({
package/index.esm.js CHANGED
@@ -395,6 +395,26 @@ class Expect {
395
395
 
396
396
  return this;
397
397
  }
398
+ toBeValid(fnValidation) {
399
+ if (!isFunction(fnValidation)) {
400
+ throw new Exception({ message: `fnValidation is not function`, code: 1064, status: 'to-be-valid' })
401
+ }
402
+ if (!fnValidation(this.value)) {
403
+ throw new Exception({ message: `${this.value} is not valid`, code: 1065, status: 'to-be-valid' })
404
+ }
405
+
406
+ return this;
407
+ }
408
+ notToBeValid(fnValidation) {
409
+ if (!isFunction(fnValidation)) {
410
+ throw new Exception({ message: `fnValidation is not function`, code: 1066, status: 'not-to-be-valid' })
411
+ }
412
+ if (fnValidation(this.value)) {
413
+ throw new Exception({ message: `${this.value} is valid`, code: 1067, status: 'not-to-be-valid' })
414
+ }
415
+
416
+ return this;
417
+ }
398
418
  toThrow(ex, shape = false, strict = false) {
399
419
  if (!isFunction(this.value)) {
400
420
  throw new Exception({ message: `given argument is not a function.`, code: 1012, status: 'not-func' })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@locustjs/test",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "This library provides a simple test runner.",
5
5
  "main": "index.cjs.js",
6
6
  "module": "index.esm.js",
package/tests/index.js CHANGED
@@ -23,6 +23,10 @@ const tests = [
23
23
  .toBeBetween(5, 15)
24
24
  .notToBeBetween(12, 20)
25
25
  .toBeOfType("number");
26
+
27
+ expect(n)
28
+ .toBeValid(x => x > 2)
29
+ .notToBeValid(x => x < 2);
26
30
  },
27
31
  ],
28
32
  [