MCPcopy Create free account
hub / github.com/gavv/httpexpect / Value

Method Value

object.go:214–237  ·  view source on GitHub ↗

Value returns a new Value instance with value for given key. Example: object := NewObject(t, map[string]interface{}{"foo": 123}) object.Value("foo").Number().IsEqual(123)

(key string)

Source from the content-addressed store, hash-verified

212// object := NewObject(t, map[string]interface{}{"foo": 123})
213// object.Value("foo").Number().IsEqual(123)
214func (o *Object) Value(key string) *Value {
215 opChain := o.chain.enter("Value(%q)", key)
216 defer opChain.leave()
217
218 if opChain.failed() {
219 return newValue(opChain, nil)
220 }
221
222 value, ok := o.value[key]
223
224 if !ok {
225 opChain.fail(AssertionFailure{
226 Type: AssertContainsKey,
227 Actual: &AssertionValue{o.value},
228 Expected: &AssertionValue{key},
229 Errors: []error{
230 errors.New("expected: map contains key"),
231 },
232 })
233 return newValue(opChain, nil)
234 }
235
236 return newValue(opChain, value)
237}
238
239// HasValue succeeds if object's value for given key is equal to given value.
240// Before comparison, both values are converted to canonical form.

Callers 2

TestObject_GettersFunction · 0.95
TestObject_IterFunction · 0.95

Calls 5

newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 2

TestObject_GettersFunction · 0.76
TestObject_IterFunction · 0.76