vest 4.2.1 → 4.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.
Files changed (44) hide show
  1. package/dist/cjs/classnames.development.js +76 -28
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compose.development.js +27 -59
  4. package/dist/cjs/enforce/compose.production.js +1 -1
  5. package/dist/cjs/parser.development.js +84 -22
  6. package/dist/cjs/parser.production.js +1 -1
  7. package/dist/cjs/promisify.development.js +21 -8
  8. package/dist/cjs/promisify.production.js +1 -1
  9. package/dist/cjs/vest.development.js +219 -203
  10. package/dist/cjs/vest.production.js +1 -1
  11. package/dist/es/classnames.development.js +76 -28
  12. package/dist/es/classnames.production.js +1 -1
  13. package/dist/es/enforce/compose.development.js +27 -59
  14. package/dist/es/enforce/compose.production.js +1 -1
  15. package/dist/es/parser.development.js +84 -22
  16. package/dist/es/parser.production.js +1 -1
  17. package/dist/es/promisify.development.js +21 -8
  18. package/dist/es/promisify.production.js +1 -1
  19. package/dist/es/vest.development.js +219 -203
  20. package/dist/es/vest.production.js +1 -1
  21. package/dist/umd/classnames.development.js +76 -28
  22. package/dist/umd/classnames.production.js +1 -1
  23. package/dist/umd/enforce/compose.development.js +89 -99
  24. package/dist/umd/enforce/compose.production.js +1 -1
  25. package/dist/umd/enforce/compounds.development.js +34 -36
  26. package/dist/umd/enforce/compounds.production.js +1 -1
  27. package/dist/umd/enforce/schema.development.js +34 -36
  28. package/dist/umd/enforce/schema.production.js +1 -1
  29. package/dist/umd/parser.development.js +84 -22
  30. package/dist/umd/parser.production.js +1 -1
  31. package/dist/umd/promisify.development.js +21 -8
  32. package/dist/umd/promisify.production.js +1 -1
  33. package/dist/umd/vest.development.js +213 -204
  34. package/dist/umd/vest.production.js +1 -1
  35. package/package.json +3 -3
  36. package/testUtils/mockThrowError.ts +3 -6
  37. package/testUtils/suiteDummy.ts +5 -1
  38. package/types/classnames.d.ts +13 -54
  39. package/types/enforce/compose.d.ts +2 -1
  40. package/types/enforce/compounds.d.ts +2 -1
  41. package/types/enforce/schema.d.ts +2 -1
  42. package/types/parser.d.ts +12 -53
  43. package/types/promisify.d.ts +12 -9
  44. package/types/vest.d.ts +17 -14
@@ -447,16 +447,18 @@ var STATUS_PENDING = 'PENDING';
447
447
  var STATUS_CANCELED = 'CANCELED';
448
448
  var STATUS_OMITTED = 'OMITTED';
449
449
 
450
- /**
451
- * Throws a timed out error.
452
- */
453
- function throwError(devMessage, productionMessage) {
454
- throw new Error(devMessage );
455
- }
456
- function throwErrorDeferred(devMessage, productionMessage) {
457
- setTimeout(function () {
458
- throwError(devMessage);
459
- }, 0);
450
+ function invariant(condition,
451
+ // eslint-disable-next-line @typescript-eslint/ban-types
452
+ message) {
453
+ if (condition) {
454
+ return;
455
+ }
456
+ // If message is a string object (rather than string literal)
457
+ // Throw the value directly as a string
458
+ // Alternatively, throw an error with the message
459
+ throw message instanceof String
460
+ ? message.valueOf()
461
+ : new Error(message ? optionalFunctionValue(message) : message);
460
462
  }
461
463
 
462
464
  // eslint-disable-next-line max-lines-per-function
@@ -546,6 +548,12 @@ function isNullish(value) {
546
548
  return isNull(value) || isUndefined(value);
547
549
  }
548
550
 
551
+ function deferThrow(message) {
552
+ setTimeout(function () {
553
+ throw new Error(message);
554
+ }, 0);
555
+ }
556
+
549
557
  function usePath() {
550
558
  var context$1 = context.useX();
551
559
  return context$1.testCursor.getCursor();
@@ -591,7 +599,7 @@ function useRetainTestKey(key, testObject) {
591
599
  current[key] = testObject;
592
600
  }
593
601
  else {
594
- throwErrorDeferred("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
602
+ deferThrow("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
595
603
  }
596
604
  }
597
605
 
@@ -624,6 +632,140 @@ var Severity;
624
632
  Severity["WARNINGS"] = "warnings";
625
633
  Severity["ERRORS"] = "errors";
626
634
  })(Severity || (Severity = {}));
635
+ var SeverityCount;
636
+ (function (SeverityCount) {
637
+ SeverityCount["ERROR_COUNT"] = "errorCount";
638
+ SeverityCount["WARN_COUNT"] = "warnCount";
639
+ })(SeverityCount || (SeverityCount = {}));
640
+
641
+ /**
642
+ * A safe hasOwnProperty access
643
+ */
644
+ function hasOwnProperty(obj, key) {
645
+ return Object.prototype.hasOwnProperty.call(obj, key);
646
+ }
647
+
648
+ function isNumber(value) {
649
+ return Boolean(typeof value === 'number');
650
+ }
651
+
652
+ function isEmpty(value) {
653
+ if (!value) {
654
+ return true;
655
+ }
656
+ else if (isNumber(value)) {
657
+ return value === 0;
658
+ }
659
+ else if (hasOwnProperty(value, 'length')) {
660
+ return lengthEquals(value, 0);
661
+ }
662
+ else if (typeof value === 'object') {
663
+ return lengthEquals(Object.keys(value), 0);
664
+ }
665
+ return true;
666
+ }
667
+ var isNotEmpty = bindNot(isEmpty);
668
+
669
+ function nonMatchingFieldName(testObject, fieldName) {
670
+ return !!fieldName && !matchingFieldName(testObject, fieldName);
671
+ }
672
+ function matchingFieldName(testObject, fieldName) {
673
+ return !!(fieldName && testObject.fieldName === fieldName);
674
+ }
675
+
676
+ function either(a, b) {
677
+ return !!a !== !!b;
678
+ }
679
+
680
+ /**
681
+ * Checks that a given test object matches the currently specified severity level
682
+ */
683
+ function nonMatchingSeverityProfile(severity, testObject) {
684
+ return either(severity === Severity.WARNINGS, testObject.warns());
685
+ }
686
+
687
+ /**
688
+ * Determines whether a certain test profile has failures.
689
+ */
690
+ function hasFailuresLogic(testObject, severityKey, fieldName) {
691
+ if (!testObject.hasFailures()) {
692
+ return false;
693
+ }
694
+ if (nonMatchingFieldName(testObject, fieldName)) {
695
+ return false;
696
+ }
697
+ if (nonMatchingSeverityProfile(severityKey, testObject)) {
698
+ return false;
699
+ }
700
+ return true;
701
+ }
702
+
703
+ function hasErrors(fieldName) {
704
+ return has(Severity.ERRORS, fieldName);
705
+ }
706
+ function hasWarnings(fieldName) {
707
+ return has(Severity.WARNINGS, fieldName);
708
+ }
709
+ function has(severityKey, fieldName) {
710
+ var testObjects = useTestsFlat();
711
+ return testObjects.some(function (testObject) {
712
+ return hasFailuresLogic(testObject, severityKey, fieldName);
713
+ });
714
+ }
715
+
716
+ // eslint-disable-next-line max-statements, complexity
717
+ function isValid(fieldName) {
718
+ if (fieldIsOmitted(fieldName)) {
719
+ return true;
720
+ }
721
+ if (hasErrors(fieldName)) {
722
+ return false;
723
+ }
724
+ var testObjects = useTestsFlat();
725
+ if (isEmpty(testObjects)) {
726
+ return false;
727
+ }
728
+ if (fieldDoesNotExist(fieldName)) {
729
+ return false;
730
+ }
731
+ if (hasNonOptionalIncomplete(fieldName)) {
732
+ return false;
733
+ }
734
+ return noMissingTests(fieldName);
735
+ }
736
+ function fieldIsOmitted(fieldName) {
737
+ var omittedFields = useOmittedFields();
738
+ if (!fieldName) {
739
+ return false;
740
+ }
741
+ return !!omittedFields[fieldName];
742
+ }
743
+ function hasNonOptionalIncomplete(fieldName) {
744
+ var optionalFields = useOptionalFields()[0];
745
+ return isNotEmpty(useAllIncomplete().filter(function (testObject) {
746
+ if (nonMatchingFieldName(testObject, fieldName)) {
747
+ return false;
748
+ }
749
+ return optionalFields[testObject.fieldName] !== true;
750
+ }));
751
+ }
752
+ function fieldDoesNotExist(fieldName) {
753
+ var testObjects = useTestsFlat();
754
+ return (!!fieldName &&
755
+ !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
756
+ }
757
+ function noMissingTests(fieldName) {
758
+ var testObjects = useTestsFlat();
759
+ var optionalFields = useOptionalFields()[0];
760
+ return testObjects.every(function (testObject) {
761
+ if (nonMatchingFieldName(testObject, fieldName)) {
762
+ return true;
763
+ }
764
+ return (optionalFields[testObject.fieldName] === true ||
765
+ testObject.isTested() ||
766
+ testObject.isOmitted());
767
+ });
768
+ }
627
769
 
628
770
  /**
629
771
  * Reads the testObjects list and gets full validation result from it.
@@ -632,20 +774,35 @@ function genTestsSummary() {
632
774
  var testObjects = useTestsFlat();
633
775
  var summary = assign(baseStats(), {
634
776
  groups: {},
635
- tests: {}
777
+ tests: {},
778
+ valid: false
636
779
  });
637
- appendSummary(testObjects);
780
+ testObjects.reduce(function (summary, testObject) {
781
+ appendToTest(summary.tests, testObject);
782
+ appendToGroup(summary.groups, testObject);
783
+ return summary;
784
+ }, summary);
785
+ summary.valid = isValid();
638
786
  return countFailures(summary);
639
- function appendSummary(testObjects) {
640
- testObjects.forEach(function (testObject) {
641
- var fieldName = testObject.fieldName, groupName = testObject.groupName;
642
- summary.tests[fieldName] = genTestObject(summary.tests, testObject);
643
- if (groupName) {
644
- summary.groups[groupName] = summary.groups[groupName] || {};
645
- summary.groups[groupName][fieldName] = genTestObject(summary.groups[groupName], testObject);
646
- }
647
- });
787
+ }
788
+ function appendToTest(tests, testObject) {
789
+ tests[testObject.fieldName] = appendTestObject(tests, testObject);
790
+ // If `valid` is false to begin with, keep it that way. Otherwise, assess.
791
+ tests[testObject.fieldName].valid =
792
+ tests[testObject.fieldName].valid === false
793
+ ? false
794
+ : isValid(testObject.fieldName);
795
+ }
796
+ /**
797
+ * Appends to a group object if within a group
798
+ */
799
+ function appendToGroup(groups, testObject) {
800
+ var groupName = testObject.groupName;
801
+ if (!groupName) {
802
+ return;
648
803
  }
804
+ groups[groupName] = groups[groupName] || {};
805
+ groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
649
806
  }
650
807
  /**
651
808
  * Counts the failed tests and adds global counters
@@ -658,29 +815,36 @@ function countFailures(summary) {
658
815
  }
659
816
  return summary;
660
817
  }
818
+ /**
819
+ * Appends the test to a results object
820
+ */
661
821
  // eslint-disable-next-line max-statements
662
- function genTestObject(summaryKey, testObject) {
822
+ function appendTestObject(summaryKey, testObject) {
663
823
  var fieldName = testObject.fieldName, message = testObject.message;
664
824
  summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
665
825
  var testKey = summaryKey[fieldName];
666
826
  if (testObject.isNonActionable())
667
827
  return testKey;
668
828
  summaryKey[fieldName].testCount++;
669
- // Adds to severity group
670
- function addTo(severity) {
671
- var countKey = severity === Severity.ERRORS ? 'errorCount' : 'warnCount';
672
- testKey[countKey]++;
673
- if (message) {
674
- testKey[severity] = (testKey[severity] || []).concat(message);
675
- }
676
- }
677
829
  if (testObject.isFailing()) {
678
- addTo(Severity.ERRORS);
830
+ incrementFailures(Severity.ERRORS);
679
831
  }
680
832
  else if (testObject.isWarning()) {
681
- addTo(Severity.WARNINGS);
833
+ incrementFailures(Severity.WARNINGS);
682
834
  }
683
835
  return testKey;
836
+ function incrementFailures(severity) {
837
+ var countKey = getCountKey(severity);
838
+ testKey[countKey]++;
839
+ if (message) {
840
+ testKey[severity] = (testKey[severity] || []).concat(message);
841
+ }
842
+ }
843
+ }
844
+ function getCountKey(severity) {
845
+ return severity === Severity.ERRORS
846
+ ? SeverityCount.ERROR_COUNT
847
+ : SeverityCount.WARN_COUNT;
684
848
  }
685
849
  function baseStats() {
686
850
  return {
@@ -726,24 +890,6 @@ function __spreadArray(to, from, pack) {
726
890
  return to.concat(ar || Array.prototype.slice.call(from));
727
891
  }
728
892
 
729
- function nonMatchingFieldName(testObject, fieldName) {
730
- return !!fieldName && !matchingFieldName(testObject, fieldName);
731
- }
732
- function matchingFieldName(testObject, fieldName) {
733
- return !!(fieldName && testObject.fieldName === fieldName);
734
- }
735
-
736
- function either(a, b) {
737
- return !!a !== !!b;
738
- }
739
-
740
- /**
741
- * Checks that a given test object matches the currently specified severity level
742
- */
743
- function nonMatchingSeverityProfile(severity, testObject) {
744
- return either(severity === Severity.WARNINGS, testObject.warns());
745
- }
746
-
747
893
  function collectFailureMessages(severity, testObjects, options) {
748
894
  var _a;
749
895
  if (options === void 0) { options = {}; }
@@ -811,9 +957,7 @@ function getWarningsByGroup(groupName, fieldName) {
811
957
  * Gets failure messages by group.
812
958
  */
813
959
  function getByGroup(severityKey, group, fieldName) {
814
- if (!group) {
815
- throwError("get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
816
- }
960
+ invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
817
961
  var testObjects = useTestsFlat();
818
962
  return collectFailureMessages(severityKey, testObjects, {
819
963
  group: group,
@@ -821,35 +965,6 @@ function getByGroup(severityKey, group, fieldName) {
821
965
  });
822
966
  }
823
967
 
824
- /**
825
- * Determines whether a certain test profile has failures.
826
- */
827
- function hasFailuresLogic(testObject, severityKey, fieldName) {
828
- if (!testObject.hasFailures()) {
829
- return false;
830
- }
831
- if (nonMatchingFieldName(testObject, fieldName)) {
832
- return false;
833
- }
834
- if (nonMatchingSeverityProfile(severityKey, testObject)) {
835
- return false;
836
- }
837
- return true;
838
- }
839
-
840
- function hasErrors(fieldName) {
841
- return has(Severity.ERRORS, fieldName);
842
- }
843
- function hasWarnings(fieldName) {
844
- return has(Severity.WARNINGS, fieldName);
845
- }
846
- function has(severityKey, fieldName) {
847
- var testObjects = useTestsFlat();
848
- return testObjects.some(function (testObject) {
849
- return hasFailuresLogic(testObject, severityKey, fieldName);
850
- });
851
- }
852
-
853
968
  function hasErrorsByGroup(groupName, fieldName) {
854
969
  return hasByGroup(Severity.ERRORS, groupName, fieldName);
855
970
  }
@@ -868,86 +983,6 @@ function hasByGroup(severityKey, group, fieldName) {
868
983
  });
869
984
  }
870
985
 
871
- /**
872
- * A safe hasOwnProperty access
873
- */
874
- function hasOwnProperty(obj, key) {
875
- return Object.prototype.hasOwnProperty.call(obj, key);
876
- }
877
-
878
- function isNumber(value) {
879
- return Boolean(typeof value === 'number');
880
- }
881
-
882
- function isEmpty(value) {
883
- if (!value) {
884
- return true;
885
- }
886
- else if (isNumber(value)) {
887
- return value === 0;
888
- }
889
- else if (hasOwnProperty(value, 'length')) {
890
- return lengthEquals(value, 0);
891
- }
892
- else if (typeof value === 'object') {
893
- return lengthEquals(Object.keys(value), 0);
894
- }
895
- return true;
896
- }
897
- var isNotEmpty = bindNot(isEmpty);
898
-
899
- // eslint-disable-next-line max-statements, complexity
900
- function isValid(result, fieldName) {
901
- if (fieldIsOmitted(fieldName)) {
902
- return true;
903
- }
904
- if (result.hasErrors(fieldName)) {
905
- return false;
906
- }
907
- var testObjects = useTestsFlat();
908
- if (isEmpty(testObjects)) {
909
- return false;
910
- }
911
- if (fieldDoesNotExist(result, fieldName)) {
912
- return false;
913
- }
914
- if (hasNonOptionalIncomplete(fieldName)) {
915
- return false;
916
- }
917
- return noMissingTests(fieldName);
918
- }
919
- function fieldIsOmitted(fieldName) {
920
- var omittedFields = useOmittedFields();
921
- if (!fieldName) {
922
- return false;
923
- }
924
- return !!omittedFields[fieldName];
925
- }
926
- function hasNonOptionalIncomplete(fieldName) {
927
- var optionalFields = useOptionalFields()[0];
928
- return isNotEmpty(useAllIncomplete().filter(function (testObject) {
929
- if (nonMatchingFieldName(testObject, fieldName)) {
930
- return false;
931
- }
932
- return optionalFields[testObject.fieldName] !== true;
933
- }));
934
- }
935
- function fieldDoesNotExist(result, fieldName) {
936
- return !!fieldName && isEmpty(result.tests[fieldName]);
937
- }
938
- function noMissingTests(fieldName) {
939
- var testObjects = useTestsFlat();
940
- var optionalFields = useOptionalFields()[0];
941
- return testObjects.every(function (testObject) {
942
- if (nonMatchingFieldName(testObject, fieldName)) {
943
- return true;
944
- }
945
- return (optionalFields[testObject.fieldName] === true ||
946
- testObject.isTested() ||
947
- testObject.isOmitted());
948
- });
949
- }
950
-
951
986
  var cache$1 = createCache(20);
952
987
  function produceSuiteResult() {
953
988
  var testObjects = useTestsFlat();
@@ -963,9 +998,7 @@ function produceSuiteResult() {
963
998
  hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
964
999
  hasWarnings: context.bind(ctxRef, hasWarnings),
965
1000
  hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
966
- isValid: context.bind(ctxRef, function (fieldName) {
967
- return isValid(produceSuiteResult(), fieldName);
968
- }),
1001
+ isValid: context.bind(ctxRef, isValid),
969
1002
  suiteName: suiteName
970
1003
  });
971
1004
  }));
@@ -1174,9 +1207,7 @@ function initBus() {
1174
1207
  }
1175
1208
  function useBus() {
1176
1209
  var context$1 = context.useX();
1177
- if (!context$1.bus) {
1178
- throwError();
1179
- }
1210
+ invariant(context$1.bus);
1180
1211
  return context$1.bus;
1181
1212
  }
1182
1213
  var Events;
@@ -1195,9 +1226,7 @@ function create() {
1195
1226
  args[_i] = arguments[_i];
1196
1227
  }
1197
1228
  var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
1198
- if (!isFunction(suiteCallback)) {
1199
- throwError('vest.create: Expected callback to be a function.');
1200
- }
1229
+ invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
1201
1230
  // Event bus initialization
1202
1231
  var bus = initBus();
1203
1232
  // State initialization
@@ -1252,9 +1281,7 @@ function create() {
1252
1281
  * })
1253
1282
  */
1254
1283
  function each(list, callback) {
1255
- if (!isFunction(callback)) {
1256
- throwError('each callback must be a function');
1257
- }
1284
+ invariant(isFunction(callback), 'each callback must be a function');
1258
1285
  isolate({ type: IsolateTypes.EACH }, function () {
1259
1286
  list.forEach(function (arg, index) {
1260
1287
  callback(arg, index);
@@ -1451,19 +1478,15 @@ function hasIncludedTests(keyTests) {
1451
1478
  * });
1452
1479
  */
1453
1480
  function group(groupName, tests) {
1454
- if (!isStringValue(groupName)) {
1455
- throwGroupError('name must be a string');
1456
- }
1457
- if (!isFunction(tests)) {
1458
- throwGroupError('callback must be a function');
1459
- }
1481
+ invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
1482
+ invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
1460
1483
  // Running with the context applied
1461
1484
  isolate({ type: IsolateTypes.GROUP }, function () {
1462
1485
  context.run({ groupName: groupName }, tests);
1463
1486
  });
1464
1487
  }
1465
- function throwGroupError(error) {
1466
- throwError("Wrong arguments passed to group. Group ".concat(error, "."));
1488
+ function groupErrorMsg(error) {
1489
+ return "Wrong arguments passed to group. Group ".concat(error, ".");
1467
1490
  }
1468
1491
 
1469
1492
  function include(fieldName) {
@@ -1579,8 +1602,6 @@ function optional(optionals) {
1579
1602
  });
1580
1603
  }
1581
1604
 
1582
- var isNotString = bindNot(isStringValue);
1583
-
1584
1605
  function isPromise(value) {
1585
1606
  return value && isFunction(value.then);
1586
1607
  }
@@ -1674,7 +1695,7 @@ function registerTest(testObject) {
1674
1695
  }
1675
1696
  }
1676
1697
  catch (e) {
1677
- throwError("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
1698
+ throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
1678
1699
  }
1679
1700
  }
1680
1701
 
@@ -1701,7 +1722,7 @@ function useTestAtCursor(newTestObject) {
1701
1722
  useSetTestAtCursor(nextTest_1);
1702
1723
  return nextTest_1;
1703
1724
  }
1704
- if (shouldPurgePrevTest(prevTest, newTestObject)) {
1725
+ if (testReorderDetected(prevTest, newTestObject)) {
1705
1726
  throwTestOrderError(prevTest, newTestObject);
1706
1727
  removeAllNextTestsInIsolate();
1707
1728
  // Need to see if this has any effect at all.
@@ -1738,14 +1759,14 @@ function useGetTestAtCursor(tests) {
1738
1759
  var cursorPath = usePath();
1739
1760
  return valueAtPath(tests, cursorPath);
1740
1761
  }
1741
- function shouldPurgePrevTest(prevTest, newTest) {
1762
+ function testReorderDetected(prevTest, newTest) {
1742
1763
  return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
1743
1764
  }
1744
1765
  function throwTestOrderError(prevTest, newTestObject) {
1745
1766
  if (shouldAllowReorder()) {
1746
1767
  return;
1747
1768
  }
1748
- throwErrorDeferred("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
1769
+ deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
1749
1770
  }
1750
1771
  function handleKeyTest(key, newTestObject) {
1751
1772
  var prevTestByKey = usePrevTestByKey(key);
@@ -1759,12 +1780,13 @@ function handleKeyTest(key, newTestObject) {
1759
1780
 
1760
1781
  // eslint-disable-next-line max-statements
1761
1782
  function registerPrevRunTest(testObject) {
1762
- var prevRunTest = useTestAtCursor(testObject);
1763
1783
  if (shouldSkipBasedOnMode(testObject)) {
1764
- moveForward();
1765
1784
  testObject.skip();
1785
+ useTestAtCursor(testObject);
1786
+ moveForward();
1766
1787
  return testObject;
1767
1788
  }
1789
+ var prevRunTest = useTestAtCursor(testObject);
1768
1790
  if (isOmitted()) {
1769
1791
  prevRunTest.omit();
1770
1792
  moveForward();
@@ -1830,12 +1852,8 @@ function testBase(fieldName) {
1830
1852
  args[_i - 1] = arguments[_i];
1831
1853
  }
1832
1854
  var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
1833
- if (isNotString(fieldName)) {
1834
- throwIncompatibleParamsError('fieldName', 'string');
1835
- }
1836
- if (!isFunction(testFn)) {
1837
- throwIncompatibleParamsError('Test callback', 'function');
1838
- }
1855
+ invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
1856
+ invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
1839
1857
  var context$1 = context.useX();
1840
1858
  var testObject = new VestTest(fieldName, testFn, {
1841
1859
  message: message,
@@ -1856,8 +1874,8 @@ function testBase(fieldName) {
1856
1874
  var test = assign(testBase, {
1857
1875
  memo: bindTestMemo(testBase)
1858
1876
  });
1859
- function throwIncompatibleParamsError(name, expected) {
1860
- throwError("Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected));
1877
+ function incompatibleParamsError(name, expected) {
1878
+ return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
1861
1879
  }
1862
1880
 
1863
1881
  var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
@@ -1867,12 +1885,10 @@ var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won
1867
1885
  */
1868
1886
  function warn() {
1869
1887
  var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
1870
- if (!ctx.currentTest) {
1871
- throwError(ERROR_OUTSIDE_OF_TEST);
1872
- }
1888
+ invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
1873
1889
  ctx.currentTest.warn();
1874
1890
  }
1875
1891
 
1876
- var VERSION = "4.2.1";
1892
+ var VERSION = "4.3.0";
1877
1893
 
1878
1894
  export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, test, warn };