has<R> method

  1. @useResult
Subject<R> has<R>(
  1. R extract(
    1. T
    ),
  2. String name
)

Extracts a property of the value for further expectations.

Sets up a clause that the value "has name that:" followed by any expectations applied to the returned Subject.

Implementation

@meta.useResult
Subject<R> has<R>(R Function(T) extract, String name) {
  return context.nest(() => ['has $name'], (value) {
    try {
      return Extracted.value(extract(value));
    } catch (e, st) {
      return Extracted.rejection(which: [
        ...prefixFirst('threw while trying to read $name: ', literal(e)),
        ...const LineSplitter().convert(st.toString())
      ]);
    }
  });
}