@event-driven-io/emmett 0.43.0-beta.21 → 0.43.0-beta.23
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/dist/index.cjs +23 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +23 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1995,6 +1995,7 @@ const assertThatArray = (array) => {
|
|
|
1995
1995
|
|
|
1996
1996
|
//#endregion
|
|
1997
1997
|
//#region src/testing/deciderSpecification.ts
|
|
1998
|
+
const isPromiseLike = (value) => value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
1998
1999
|
const DeciderSpecification = { for: deciderSpecificationFor };
|
|
1999
2000
|
function deciderSpecificationFor(decider) {
|
|
2000
2001
|
return (givenEvents) => {
|
|
@@ -2004,16 +2005,14 @@ function deciderSpecificationFor(decider) {
|
|
|
2004
2005
|
return decider.decide(command, currentState);
|
|
2005
2006
|
};
|
|
2006
2007
|
return {
|
|
2007
|
-
then: (
|
|
2008
|
+
then: (expectedEventsOrAssert) => {
|
|
2008
2009
|
const resultEvents = handle();
|
|
2009
|
-
if (resultEvents
|
|
2010
|
-
|
|
2011
|
-
});
|
|
2012
|
-
thenHandler$1(resultEvents, expectedEvents);
|
|
2010
|
+
if (isPromiseLike(resultEvents)) return Promise.resolve(resultEvents).then((events) => thenHandler$1(events, expectedEventsOrAssert));
|
|
2011
|
+
return thenHandler$1(resultEvents, expectedEventsOrAssert);
|
|
2013
2012
|
},
|
|
2014
2013
|
thenNothingHappened: () => {
|
|
2015
2014
|
const resultEvents = handle();
|
|
2016
|
-
if (resultEvents
|
|
2015
|
+
if (isPromiseLike(resultEvents)) return Promise.resolve(resultEvents).then((events) => {
|
|
2017
2016
|
thenNothingHappensHandler$1(events);
|
|
2018
2017
|
});
|
|
2019
2018
|
thenNothingHappensHandler$1(resultEvents);
|
|
@@ -2021,7 +2020,7 @@ function deciderSpecificationFor(decider) {
|
|
|
2021
2020
|
thenThrows: (...args) => {
|
|
2022
2021
|
try {
|
|
2023
2022
|
const result = handle();
|
|
2024
|
-
if (result
|
|
2023
|
+
if (isPromiseLike(result)) return Promise.resolve(result).then(() => {
|
|
2025
2024
|
throw new AssertionError("Handler did not fail as expected");
|
|
2026
2025
|
}).catch((error) => {
|
|
2027
2026
|
thenThrowsErrorHandler$1(error, args);
|
|
@@ -2035,11 +2034,26 @@ function deciderSpecificationFor(decider) {
|
|
|
2035
2034
|
} };
|
|
2036
2035
|
};
|
|
2037
2036
|
}
|
|
2038
|
-
function thenHandler$1(events,
|
|
2037
|
+
function thenHandler$1(events, expectedEventsOrAssert) {
|
|
2039
2038
|
const resultEventsArray = Array.isArray(events) ? events : [events];
|
|
2040
|
-
|
|
2039
|
+
if (typeof expectedEventsOrAssert === "function") return runThenAssert(resultEventsArray, expectedEventsOrAssert);
|
|
2040
|
+
const expectedEventsArray = Array.isArray(expectedEventsOrAssert) ? expectedEventsOrAssert : [expectedEventsOrAssert];
|
|
2041
2041
|
assertThatArray(resultEventsArray).containsOnlyElementsMatching(expectedEventsArray);
|
|
2042
2042
|
}
|
|
2043
|
+
/**
|
|
2044
|
+
* Runs the client-provided assertion. The test fails (throws) when the callback
|
|
2045
|
+
* throws, returns an `Error`, or returns a Promise that rejects or resolves to
|
|
2046
|
+
* an `Error`. A thrown error is propagated as-is so the client's assertion
|
|
2047
|
+
* library (node:assert, Vitest `expect`, ...) keeps its own message and diff.
|
|
2048
|
+
*/
|
|
2049
|
+
function runThenAssert(events, assert) {
|
|
2050
|
+
const outcome = assert(events);
|
|
2051
|
+
if (isPromiseLike(outcome)) return Promise.resolve(outcome).then(failIfError);
|
|
2052
|
+
failIfError(outcome);
|
|
2053
|
+
}
|
|
2054
|
+
function failIfError(outcome) {
|
|
2055
|
+
if (outcome instanceof Error) throw outcome;
|
|
2056
|
+
}
|
|
2043
2057
|
function thenNothingHappensHandler$1(events) {
|
|
2044
2058
|
assertThatArray(Array.isArray(events) ? events : [events]).isEmpty();
|
|
2045
2059
|
}
|