File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments