Skip to content

Commit 9449f00

Browse files
committedSep 10, 2019
Debugging aggregate to print selector
1 parent ab25ad8 commit 9449f00

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed
 

‎API.md

+8
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ printSelected: () => string[]
315315
316316
Every test view has some default aggregate methods that are automatically provided.
317317
318+
#### Print Selector
319+
320+
Returns a string representation of the selector computed by the test view. This includes composed test views as well as any parameterization. Useful for debugging purposes. The method of stringifying is determined by the adapter.
321+
322+
```typescript
323+
printSelector: () => string
324+
```
325+
318326
#### Print Root
319327
320328
Returns a string representation of the root element used to materialize the test view. Useful for debugging purposes. The method of stringifying is determined by the adapter.

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ all adapters.
9090
9191
If a selector fails to select the required number of elements an error will be raised in the test. The error object includes more context about the error. The error messages should include a string representation of the selector, the root of the test view, and the selected elements.
9292
93-
There are some default actions and aggregate methods useful for debugging tests with test views. A `printSelected` action is provided to return a string representation of the selected elements in a test view. A `printRoot` aggregate method is provided to return a string representation of the root of the test view.
93+
There are some default actions and aggregate methods useful for debugging tests with test views. A `printSelected` action is provided to return a string representation of the selected elements in a test view. A `printSelector` aggregate method is provided to return a string representation of the selector (including the result of any parameterization). A `printRoot` aggregate method is provided to return a string representation of the root of the test view.
9494
9595
## Contributing
9696

‎core/index.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,16 @@ describe("Debugging failing selectors", () => {
311311

312312
expect(a.materialize("aba").printRoot()).toEqual("aba");
313313
});
314+
315+
test("A printSelector aggregate can be used to see the string representation of the selector", () => {
316+
const sel = testView("a")(testView("b"));
317+
318+
expect(sel.materialize("aba").printSelector()).toEqual("ab");
319+
});
320+
321+
test("A printSelector aggregate can be used to see the string representation of the parameterized selector", () => {
322+
const sel = testView(x => x + "a")(testView("b"));
323+
324+
expect(sel.materialize("aba", "foo").printSelector()).toEqual("fooab");
325+
});
314326
});

‎core/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type AggregateParameters<E, A extends Aggregate<E>> = AParameters<A>;
1717
type AggregateMap<E> = { [k: string]: Aggregate<E> };
1818
type DefaultAggregates<E> = {
1919
printRoot: (e: E[]) => string;
20+
printSelector: (e: E[]) => string;
2021
};
2122

2223
// Materialized aggregate types
@@ -131,6 +132,7 @@ const makeTestViewConstructor = <S, E>(
131132
composeSelectors: ComposeSelectors<S>,
132133
actionRealizer: ActionMaterializer<S, E>,
133134
aggregateRealizer: AggregateMaterializer<S, E>,
135+
printSelector: Printer<S>,
134136
printElement: Printer<E>,
135137
defaultViews: DefaultViews<S, E>
136138
): TestViewConstructor<S, E> => {
@@ -208,6 +210,11 @@ const makeTestViewConstructor = <S, E>(
208210
E,
209211
DefaultAggregates<E>
210212
> = {
213+
printSelector: aggregateRealizer(
214+
renderedSelector,
215+
() => printSelector(renderedSelector),
216+
root
217+
),
211218
printRoot: aggregateRealizer(
212219
renderedSelector,
213220
() => printElement(root),
@@ -474,6 +481,7 @@ export const makeAdapter = <S, E, EG>(
474481
printElement
475482
),
476483
makeAggregateRealizer<S, E, EG>(runSelector, iterateSelector),
484+
printSelector,
477485
printElement,
478486
defaultViews
479487
);

0 commit comments

Comments
 (0)
Please sign in to comment.