createStaticInteropMock<T, U> function
Null safety
- U dartMock,
- [Object? proto = null]
DO NOT USE - THIS IS UNIMPLEMENTED.
Given a @staticInterop
type T and an instance dartMock
of a Dart class
U that implements the external extension members of T, creates a forwarding
mock.
Optionally, you may provide a JS prototype object e.g. the JS value
Window.prototype
using proto
. This allows instanceof and is checks with
@Native
types to pass with the returned forwarding mock.
When external extension members are called, they will forward to the
corresponding implementing member in dartMock
. If U does not implement all
the external extension members of T, or if U does not properly override
them, it will be considered a compile-time error.
For example:
@JS()
@staticInterop
class JSClass {}
extension JSClassExtension on JSClass {
external String stringify(int param);
}
class DartClass {
String stringify(num param) => param.toString();
}
...
JSClass mock = createStaticInteropMock<JSClass, DartClass>(DartClass());
TODO(srujzs): Add more detail on how inherited extension members need to be implemented, as well as how conflicts are resolved (if they are resolvable). The semantics here tries to conform to the view type specification.
Implementation
external T createStaticInteropMock<T, U>(U dartMock, [Object? proto = null]);