Skip to content

Commit 2a04d1a

Browse files
committed
Added Array and Boolean assertions
1 parent e565a0a commit 2a04d1a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

requirejson/json.go

+15
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ func (obj *JQObject) MustNotBeEmpty(msgAndArgs ...interface{}) {
113113
}
114114
}
115115

116+
// IsTrue test if the JQObject is `true`.
117+
func (obj *JQObject) IsTrue(msgAndArgs ...interface{}) {
118+
obj.MustEqual("true", msgAndArgs...)
119+
}
120+
121+
// IsFalse test if the JQObject is `false`.
122+
func (obj *JQObject) IsFalse(msgAndArgs ...interface{}) {
123+
obj.MustEqual("false", msgAndArgs...)
124+
}
125+
126+
// ArrayMustContain checks if the give JQObject contains the given element.
127+
func (obj *JQObject) ArrayMustContain(jsonElement string, msgAndArgs ...interface{}) {
128+
obj.Query(`any(. == ` + jsonElement + `)`).IsTrue(msgAndArgs...)
129+
}
130+
116131
// Query performs a test on a given json output. A jq-like query is performed
117132
// on the given jsonData and the result is compared with jsonExpected.
118133
// If the output doesn't match the test fails. If msgAndArgs are provided they

requirejson/json_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ func TestJSONAssertions(t *testing.T) {
6565
requirejson.Len(t, in3, 3)
6666

6767
requirejson.Query(t, in, ".list | length", "3")
68+
69+
requirejson.Parse(t, in).Query(".list").ArrayMustContain("20")
6870
}

0 commit comments

Comments
 (0)