Repository: obsidian-tasks-group/obsidian-tasks (ts)

Issue:
Make 'explain' explain sort commands
### Motivation

At the moment the `sort by` instructions are not included in `explain` output.

There is hidden behaviour in the `sort` behaviour, because the built-in `sort` steps are always appended to any sort instructions applied by the user, and I think it would be really helpful for this to be visible to users:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/d115c2df4b68439f515afc995f3b62d94ba88191/src/Query/Sort.ts#L11-L27

### Implementation

Currently Query stores only the name of the type of the `sort by` line and not the whole line:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/6da15e6feeaddb4a52df96e799ff0b8a1e5a1967/src/Query/Query.ts#L22

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/a7a64f6e02c80d37f7309a1a9e4ccfab39c442dd/src/Query/Sorter.ts#L18-L33

So this change will likely involve changing `Sorter` to store the instruction and the explanation, similar to how `Filter` does:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/7c19f3fb4fd0b1aa73c663ff19a0f34511bced3b/src/Query/Filter/Filter.ts#L20-L23

_Originally posted by @claremacrae in https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2093#issuecomment-1623348346_
            

Pull request description:
feat: Make 'explain' show 'sort by' commands
<!--- Provide a general summary of your changes in the Title above -->

# Description

1. Make `explain` list the Query's `sort by` instructions.
2. Update the documentation


## Motivation and Context

Fixes #2106.

This is part of preparation for #2074 - I want to be able to show what `sort by` instructions are in use, and test the removal of them via something like `clear sort by`.

## How has this been tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how -->
<!--- your change affects other areas of the code, etc. -->

- Via tests
- Via exploratory testing

## Screenshots (if appropriate)

![image](https://github.com/obsidian-tasks-group/obsidian-tasks/assets/4840096/bdcbebb1-eb22-4b86-b2f3-8a97985bead4)

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

Changes visible to users:

- [x] **New feature** (prefix: `feat` - non-breaking change which adds functionality)
- [x] **Documentation** (prefix: `docs` - improvements to any documentation content **for users**)

Internal changes:

- [x] **Refactor** (prefix: `refactor` - non-breaking change which only improves the design or structure of existing code, and making no changes to its external behaviour)
- [x] **Tests** (prefix: `test` - additions and improvements to unit tests and the smoke tests)

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [x] My code follows the code style of this project and passes `yarn run lint`.
- [x] My change requires a change to the documentation.
- [x] I have [updated the documentation](https://publish.obsidian.md/tasks-contributing/Documentation/About+Documentation) accordingly.
- [x] My change has adequate [Unit Test coverage](https://publish.obsidian.md/tasks-contributing/Testing/About+Testing).

## Terms

<!--
By submitting this pull request, you must agree to follow our
[contributing guide](https://publish.obsidian.md/tasks-contributing) and
[Code of Conduct](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CODE_OF_CONDUCT.md).
Put an x in the boxes to confirm you agree.
-->

- [x] My contribution follow this project's [contributing guide](https://publish.obsidian.md/tasks-contributing)
- [x] I agree to follow this project's [Code of Conduct](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CODE_OF_CONDUCT.md)


Patch:
diff --git a/docs/Introduction.md b/docs/Introduction.md
index 4227bc35..749630b0 100644
--- a/docs/Introduction.md
+++ b/docs/Introduction.md
@@ -14,7 +14,7 @@ _In recent [releases](https://github.com/obsidian-tasks-group/obsidian-tasks/rel
 -->
 
 - X.Y.Z: 🔥 Add [[Layout#Full Mode|'full mode']] to turn off `short mode`.
-- X.Y.Z: 🔥 Add any [[Grouping|'group by']] instructions to [[Explaining Queries|explain]] output.
+- X.Y.Z: 🔥 Add any [[Grouping|'group by']] and [[Sorting|'sort by']] instructions to [[Explaining Queries|explain]] output.
 - 5.3.0: 🔥 Add [[Postponing|postpone button]] to Tasks query results.
 - 5.3.0: 🔥 Add [[Toggling and Editing Statuses#'Change task status' context menu|'change task status' menu]] to Reading mode and Tasks query results.
 - 5.3.0: 🔥 Add documentation section about [[About Editing|editing tasks]].
diff --git a/docs/Queries/Explaining Queries.md b/docs/Queries/Explaining Queries.md
index 510582a3..d83593ec 100644
--- a/docs/Queries/Explaining Queries.md
+++ b/docs/Queries/Explaining Queries.md
@@ -21,6 +21,7 @@ This has a number of benefits:
   - This often explains why tasks are missing from results.
 - If there is a [[Global Query|global query]] enabled, it too is included in the explanation.
 - Any [[Grouping|'group by']] instructions are listed (since Tasks X.Y.Z)
+- Any [[Sorting|'sort by']] instructions are listed (since Tasks X.Y.Z)
 
 ## Examples
 
@@ -53,6 +54,8 @@ Explanation of this Tasks code block query:
     due date is before 2022-10-22 (Saturday 22nd October 2022)
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
@@ -84,6 +87,8 @@ Explanation of this Tasks code block query:
     using regex:     '^Root\/Sub-Folder\/Sample File\.md' with flag 'i'
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
@@ -113,6 +118,8 @@ Explanation of this Tasks code block query:
       is recurring
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
@@ -157,6 +164,8 @@ Explanation of this Tasks code block query:
           description includes 7
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
@@ -194,6 +203,8 @@ Explanation of the global query:
 
   No grouping instructions supplied.
 
+  No sorting instructions supplied.
+
   At most 50 tasks.
 
 Explanation of this Tasks code block query:
@@ -206,6 +217,8 @@ Explanation of this Tasks code block query:
       2022-10-30 (Sunday 30th October 2022) inclusive
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
@@ -245,6 +258,8 @@ Explanation of this Tasks code block query:
   description includes Some Cryptic String 
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
diff --git a/docs/Queries/Line Continuations.md b/docs/Queries/Line Continuations.md
index 7af5e8c4..96eb4b08 100644
--- a/docs/Queries/Line Continuations.md
+++ b/docs/Queries/Line Continuations.md
@@ -37,6 +37,8 @@ Explanation of this Tasks code block query:
       priority is lowest
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
@@ -77,6 +79,8 @@ Explanation of this Tasks code block query:
   description includes \
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
diff --git a/docs/Queries/Regular Expressions.md b/docs/Queries/Regular Expressions.md
index dc927055..4847a9a1 100644
--- a/docs/Queries/Regular Expressions.md
+++ b/docs/Queries/Regular Expressions.md
@@ -99,6 +99,8 @@ Explanation of this Tasks code block query:
     using regex:     '^Root\/Sub-Folder\/Sample File\.md' with flag 'i'
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
diff --git a/docs/Scripting/Placeholders.md b/docs/Scripting/Placeholders.md
index f00c2f83..90d2887d 100644
--- a/docs/Scripting/Placeholders.md
+++ b/docs/Scripting/Placeholders.md
@@ -54,6 +54,8 @@ Explanation of this Tasks code block query:
   description includes Some Cryptic String 
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
 ```
 <!-- endSnippet -->
 
diff --git a/src/Query/Explain/Explainer.ts b/src/Query/Explain/Explainer.ts
index 076f02d8..13dd0052 100644
--- a/src/Query/Explain/Explainer.ts
+++ b/src/Query/Explain/Explainer.ts
@@ -34,6 +34,7 @@ export class Explainer {
         const results: string[] = [];
         results.push(this.explainFilters(query));
         results.push(this.explainGroups(query));
+        results.push(this.explainSorters(query));
         results.push(this.explainQueryLimits(query));
         results.push(this.explainDebugSettings());
 
@@ -73,6 +74,19 @@ export class Explainer {
         return result;
     }
 
+    public explainSorters(query: Query) {
+        const numberOfSorters = query.sorting.length;
+        if (numberOfSorters === 0) {
+            return this.indent('No sorting instructions supplied.\n');
+        }
+
+        let result = '';
+        for (let i = 0; i < numberOfSorters; i++) {
+            result += this.indentation + query.sorting[i].instruction + '\n';
+        }
+        return result;
+    }
+
     public explainQueryLimits(query: Query) {
         function getPluralisedText(limit: number) {
             let text = `At most ${limit} task`;
diff --git a/src/Query/Filter/Field.ts b/src/Query/Filter/Field.ts
index 2b92c029..a0c6df8f 100644
--- a/src/Query/Filter/Field.ts
+++ b/src/Query/Filter/Field.ts
@@ -175,6 +175,21 @@ export abstract class Field {
         return new RegExp(`^sort by ${this.fieldNameSingularEscaped()}( reverse)?`, 'i');
     }
 
+    /**
+     * Reconstruct a 'sorter by' instruction to use for sorting of this field.
+     *
+     * This is used to simplify the construction of {@link Sorter} objects.
+     * @param reverse
+     * @protected
+     */
+    protected sorterInstruction(reverse: boolean) {
+        let instruction = `sort by ${this.fieldNameSingular()}`;
+        if (reverse) {
+            instruction += ' reverse';
+        }
+        return instruction;
+    }
+
     /**
      * Return a function to compare two Task objects, for use in sorting by this field's value.
      *
@@ -190,7 +205,7 @@ export abstract class Field {
      * @param reverse - false for normal sort order, true for reverse sort order.
      */
     public createSorter(reverse: boolean): Sorter {
-        return new Sorter(this.fieldNameSingular(), this.comparator(), reverse);
+        return new Sorter(this.sorterInstruction(reverse), this.fieldNameSingular(), this.comparator(), reverse);
     }
 
     /**
diff --git a/src/Query/Filter/TagsField.ts b/src/Query/Filter/TagsField.ts
index 819ed0cb..63bf8e89 100644
--- a/src/Query/Filter/TagsField.ts
+++ b/src/Query/Filter/TagsField.ts
@@ -72,7 +72,7 @@ export class TagsField extends MultiTextField {
         const reverse = !!match[1];
         const propertyInstance = isNaN(+match[2]) ? 1 : +match[2];
         const comparator = TagsField.makeCompareByTagComparator(propertyInstance);
-        return new Sorter(this.fieldNameSingular(), comparator, reverse);
+        return new Sorter(line, this.fieldNameSingular(), comparator, reverse);
     }
 
     /**
diff --git a/src/Query/Sorter.ts b/src/Query/Sorter.ts
index 5ab233f9..06567c6e 100644
--- a/src/Query/Sorter.ts
+++ b/src/Query/Sorter.ts
@@ -16,18 +16,21 @@ export type Comparator = (a: Task, b: Task) => number;
  * It stores the comparison function as a {@link Comparator}.
  */
 export class Sorter {
+    public readonly instruction: string;
     public readonly property: string;
     public readonly comparator: Comparator;
 
     /**
      * Constructor.
      *
+     * @param instruction - the query instruction that created this object
      * @param property - the name of the property.
      * @param comparator - {@link Comparator} function, for sorting in the standard direction.
      *                     If `reverse` is true, it will automatically be converted to reverse the sort direction.
      * @param reverse - whether the sort order should be reversed.
      */
-    constructor(property: string, comparator: Comparator, reverse: boolean) {
+    constructor(instruction: string, property: string, comparator: Comparator, reverse: boolean) {
+        this.instruction = instruction;
         this.property = property;
         this.comparator = Sorter.maybeReverse(reverse, comparator);
     }


Test patch:
diff --git a/tests/Config/DebugSettings.test.ts b/tests/Config/DebugSettings.test.ts
index ab44086f..ec59be7c 100644
--- a/tests/Config/DebugSettings.test.ts
+++ b/tests/Config/DebugSettings.test.ts
@@ -39,6 +39,8 @@ describe('DebugSettings', () => {
 
             No grouping instructions supplied.
 
+            sort by status
+
             NOTE: All sort instructions, including default sort order, are disabled, due to 'ignoreSortInstructions' setting.
             "
         `);
diff --git a/tests/Query.test.ts b/tests/Query.test.ts
index b2b32af6..fc875129 100644
--- a/tests/Query.test.ts
+++ b/tests/Query.test.ts
@@ -268,6 +268,7 @@ describe('Query parsing', () => {
             expect(query.error).toBeUndefined();
             expect(query.sorting.length).toEqual(1);
             expect(query.sorting[0]).toBeDefined();
+            expect(query.sorting[0].instruction).toEqual(filter);
 
             // Assert Uppercase
             expect(queryUpperCase.error).toBeUndefined();
@@ -1197,6 +1198,8 @@ describe('Query', () => {
                 "description includes hello
 
                 No grouping instructions supplied.
+
+                No sorting instructions supplied.
                 "
             `);
         });
@@ -1438,6 +1441,8 @@ with \ backslash)`;
                     description includes line 1 continued with \\ backslash
 
                 No grouping instructions supplied.
+
+                No sorting instructions supplied.
                 "
             `);
             expect(queryUpperCase.explainQuery()).toMatchInlineSnapshot(`
@@ -1447,6 +1452,8 @@ with \ backslash)`;
                     description includes line 1 continued with \\ backslash
 
                 No grouping instructions supplied.
+
+                No sorting instructions supplied.
                 "
             `);
         });
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_boolean_combinations.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_boolean_combinations.approved.explanation.text
index 9bda53ad..9afa33ea 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_boolean_combinations.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_boolean_combinations.approved.explanation.text
@@ -8,3 +8,5 @@ Explanation of this Tasks code block query:
       is recurring
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_expands_dates.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_expands_dates.approved.explanation.text
index 6d84d9fd..ddd082f7 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_expands_dates.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_expands_dates.approved.explanation.text
@@ -10,3 +10,5 @@ Explanation of this Tasks code block query:
     due date is before 2022-10-22 (Saturday 22nd October 2022)
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_explains_task_block_with_global_query_active.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_explains_task_block_with_global_query_active.approved.explanation.text
index c8dea8db..01ea0241 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_explains_task_block_with_global_query_active.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_explains_task_block_with_global_query_active.approved.explanation.text
@@ -4,6 +4,8 @@ Explanation of the global query:
 
   No grouping instructions supplied.
 
+  No sorting instructions supplied.
+
   At most 50 tasks.
 
 Explanation of this Tasks code block query:
@@ -16,3 +18,5 @@ Explanation of this Tasks code block query:
       2022-10-30 (Sunday 30th October 2022) inclusive
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_double_slash.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_double_slash.approved.explanation.text
index 75ba68a7..126f066e 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_double_slash.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_double_slash.approved.explanation.text
@@ -3,3 +3,5 @@ Explanation of this Tasks code block query:
   description includes \
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_single_slash.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_single_slash.approved.explanation.text
index c45ca577..0d5440cf 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_single_slash.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_line_continuation_-_single_slash.approved.explanation.text
@@ -6,3 +6,5 @@ Explanation of this Tasks code block query:
       priority is lowest
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_nested_boolean_combinations.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_nested_boolean_combinations.approved.explanation.text
index 262203b3..010d0e9f 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_nested_boolean_combinations.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_nested_boolean_combinations.approved.explanation.text
@@ -15,3 +15,5 @@ Explanation of this Tasks code block query:
           description includes 7
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_placeholders.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_placeholders.approved.explanation.text
index 2fbad4f5..5565aa0d 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_placeholders.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_placeholders.approved.explanation.text
@@ -11,3 +11,5 @@ Explanation of this Tasks code block query:
   description includes Some Cryptic String 
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/DocsSamplesForExplain.test.explain_regular_expression.approved.explanation.text b/tests/Query/Explain/DocsSamplesForExplain.test.explain_regular_expression.approved.explanation.text
index 18a64def..355807b7 100644
--- a/tests/Query/Explain/DocsSamplesForExplain.test.explain_regular_expression.approved.explanation.text
+++ b/tests/Query/Explain/DocsSamplesForExplain.test.explain_regular_expression.approved.explanation.text
@@ -4,3 +4,5 @@ Explanation of this Tasks code block query:
     using regex:     '^Root\/Sub-Folder\/Sample File\.md' with flag 'i'
 
   No grouping instructions supplied.
+
+  No sorting instructions supplied.
diff --git a/tests/Query/Explain/Explainer.test.ts b/tests/Query/Explain/Explainer.test.ts
index 9cce2393..d7a4921d 100644
--- a/tests/Query/Explain/Explainer.test.ts
+++ b/tests/Query/Explain/Explainer.test.ts
@@ -65,6 +65,9 @@ limit groups 3
             group by priority reverse
             group by happens
 
+            sort by description reverse
+            sort by path
+
             At most 50 tasks.
 
             At most 3 tasks per group (if any "group by" options are supplied).
@@ -91,6 +94,9 @@ limit groups 3
               group by priority reverse
               group by happens
 
+              sort by description reverse
+              sort by path
+
               At most 50 tasks.
 
               At most 3 tasks per group (if any "group by" options are supplied).
@@ -146,6 +152,18 @@ describe('explain groupers', () => {
     });
 });
 
+describe('explain sorters', () => {
+    it('should explain "sort by" options', () => {
+        const source = 'sort by due\nsort by priority()';
+        const query = new Query(source);
+        expect(explainer.explainSorters(query)).toMatchInlineSnapshot(`
+            "sort by due
+            sort by priority
+            "
+        `);
+    });
+});
+
 describe('explain limits', () => {
     it('should explain limit 5', () => {
         const source = 'limit 5';
diff --git a/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_filters-date-examples.approved.explanation.text b/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_filters-date-examples.approved.explanation.text
index f89e7b36..21006d57 100644
--- a/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_filters-date-examples.approved.explanation.text
+++ b/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_filters-date-examples.approved.explanation.text
@@ -33,3 +33,5 @@ due May =>
   due date is on 2023-05-01 (Monday 1st May 2023)
 
 No grouping instructions supplied.
+
+No sorting instructions supplied.
diff --git a/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-week-month-quarter-year.approved.explanation.text b/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-week-month-quarter-year.approved.explanation.text
index 1ad89ec7..965131ce 100644
--- a/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-week-month-quarter-year.approved.explanation.text
+++ b/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-week-month-quarter-year.approved.explanation.text
@@ -74,3 +74,5 @@ due next year =>
 description includes ------------------------------
 
 No grouping instructions supplied.
+
+No sorting instructions supplied.
diff --git a/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-weekday.approved.explanation.text b/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-weekday.approved.explanation.text
index aecaa07d..7f8bc94d 100644
--- a/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-weekday.approved.explanation.text
+++ b/tests/Query/Filter/ReferenceDocs/FilterReference/DateFieldReference.test.explain_date_reference_last-this-next-weekday.approved.explanation.text
@@ -104,3 +104,5 @@ due next sunday =>
 description includes ------------------------------
 
 No grouping instructions supplied.
+
+No sorting instructions supplied.
diff --git a/tests/Query/Filter/TextField.test.explains_regular_expression_searches_bulk_test.approved.txt b/tests/Query/Filter/TextField.test.explains_regular_expression_searches_bulk_test.approved.txt
index b9fd7163..e18f7c7d 100644
--- a/tests/Query/Filter/TextField.test.explains_regular_expression_searches_bulk_test.approved.txt
+++ b/tests/Query/Filter/TextField.test.explains_regular_expression_searches_bulk_test.approved.txt
@@ -108,4 +108,6 @@ tags regex matches /(home|pc_mac|town)/ =>
 
 No grouping instructions supplied.
 
+No sorting instructions supplied.
+
 Error: None
diff --git a/tests/Sort.test.ts b/tests/Sort.test.ts
index bea58cf8..45cfece7 100644
--- a/tests/Sort.test.ts
+++ b/tests/Sort.test.ts
@@ -31,7 +31,7 @@ describe('Sort', () => {
 
         // Normal way round
         {
-            const sortByDescriptionLength = new Sorter('junk', comparator, false);
+            const sortByDescriptionLength = new Sorter('sort by description length', 'junk', comparator, false);
             expect(sortByDescriptionLength.comparator(short, long)).toEqual(1);
             expect(sortByDescriptionLength.comparator(short, short)).toEqual(0);
             expect(sortByDescriptionLength.comparator(long, short)).toEqual(-1);
@@ -39,7 +39,7 @@ describe('Sort', () => {
 
         // Reversed
         {
-            const sortByDescriptionLength = new Sorter('junk', comparator, true);
+            const sortByDescriptionLength = new Sorter('sort by description length reverse', 'junk', comparator, true);
             expect(sortByDescriptionLength.comparator(short, long)).toEqual(-1);
             expect(sortByDescriptionLength.comparator(short, short)).toEqual(-0);
             expect(sortByDescriptionLength.comparator(long, short)).toEqual(1);
diff --git a/tests/lib/QueryRendererHelper.test.ts b/tests/lib/QueryRendererHelper.test.ts
index 04f952bd..6a8cc513 100644
--- a/tests/lib/QueryRendererHelper.test.ts
+++ b/tests/lib/QueryRendererHelper.test.ts
@@ -19,6 +19,8 @@ describe('explain', () => {
               No filters supplied. All tasks will match the query.
 
               No grouping instructions supplied.
+
+              No sorting instructions supplied.
             "
         `);
     });
@@ -37,6 +39,8 @@ describe('explain', () => {
               No filters supplied. All tasks will match the query.
 
               No grouping instructions supplied.
+
+              No sorting instructions supplied.
             "
         `);
     });
@@ -53,11 +57,15 @@ describe('explain', () => {
 
               No grouping instructions supplied.
 
+              No sorting instructions supplied.
+
             Explanation of this Tasks code block query:
 
               No filters supplied. All tasks will match the query.
 
               No grouping instructions supplied.
+
+              No sorting instructions supplied.
             "
         `);
     });
@@ -78,11 +86,15 @@ describe('explain', () => {
 
               No grouping instructions supplied.
 
+              No sorting instructions supplied.
+
             Explanation of this Tasks code block query:
 
               No filters supplied. All tasks will match the query.
 
               No grouping instructions supplied.
+
+              No sorting instructions supplied.
             "
         `);
     });
@@ -98,6 +110,8 @@ describe('explain', () => {
               No filters supplied. All tasks will match the query.
 
               No grouping instructions supplied.
+
+              No sorting instructions supplied.
             "
         `);
     });