Skip to content

Commit

Permalink
fix: json null formatting in assertion report (#209)
Browse files Browse the repository at this point in the history
* pr-fix: correct merge w/ 'main'

* fix: json null report formatting
  • Loading branch information
stijnmoreels authored Nov 1, 2024
1 parent d412f85 commit 82303c9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Arcus.Testing.Assert/AssertJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ private static JsonDifference CompareJsonNode(JsonNode expected, JsonNode actual
JsonArray actualArray => CompareJsonArray(expected, actualArray, options),
JsonObject actualObject => CompareJsonObject(expected, actualObject, options),
JsonValue actualValue => CompareJsonValue(expected, actualValue),
null => expected is null ? null : new JsonDifference(ActualIsNull, expected.GetPath()),
null => expected is null ? null : new JsonDifference(ActualIsNull, expected.GetPath())
{
ExpectedNodeDiff = expected.ToString(),
ActualNodeDiff = "null"
},
_ => null
};
}
Expand Down Expand Up @@ -470,8 +474,8 @@ internal class JsonDifference
internal JsonDifference(JsonDifferenceKind kind, JsonNode expected, JsonNode actual)
: this(kind, expected?.GetPath() ?? actual?.GetPath() ?? "<not-available>", expected: Describe(expected), actual: Describe(actual))
{
ExpectedNodeDiff = expected?.ToString();
ActualNodeDiff = actual?.ToString();
ExpectedNodeDiff = expected?.ToString() ?? "null";
ActualNodeDiff = actual?.ToString() ?? "null";
}

internal JsonDifference(JsonDifferenceKind kind, string path, object actual, object expected)
Expand Down
38 changes: 38 additions & 0 deletions src/Arcus.Testing.Tests.Unit/Assert_/AssertJsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,44 @@ [ [
""name"": ""post-metal""
}"
};
yield return new object[]
{
"{ \"this\": \"that\", \"options\": null }",
"{ \"this\": \"that\", \"options\": { \"and\": \"this\" } }",
@"Expected: Actual:
null {
""and"": ""this""
}"
};
yield return new object[]
{
"{ \"this\": \"that\", \"options\": { \"and\": \"this\" } }",
"{ \"this\": \"that\", \"options\": null }",
@"Expected: Actual:
{ null
""and"": ""this""
}"
};
yield return new object[]
{
"null",
"[ \"this\", \"that\" ]",
@"Expected: Actual:
null [
""this"",
""that""
]"
};
yield return new object[]
{
"[ \"this\", \"that\" ]",
"null",
@"Expected: Actual:
[ null
""this"",
""that""
] "
};
}
}

Expand Down

0 comments on commit 82303c9

Please sign in to comment.