diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp index 1dec6c86d4ca2d..5cf43e448424b4 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp @@ -84,6 +84,10 @@ class ConsoleApiTest JsiIntegrationPortableTest::TearDown(); } + /** + * Expect a console API call to be reported with parameters matching \param + * paramsMatcher. + */ void expectConsoleApiCall(Matcher paramsMatcher) { if (runtimeEnabled_) { expectConsoleApiCallImpl(std::move(paramsMatcher)); @@ -92,6 +96,28 @@ class ConsoleApiTest } } + /** + * Expect a console API call to be reported with parameters matching \param + * paramsMatcher, only if the Runtime domain is currently enabled ( = the call + * is reported in real time). + */ + void expectConsoleApiCallImmediate(Matcher paramsMatcher) { + if (runtimeEnabled_) { + expectConsoleApiCallImpl(std::move(paramsMatcher)); + } + } + + /** + * Expect a console API call to be reported with parameters matching \param + * paramsMatcher, only if the Runtime domain is currently disabled ( = the + * call will be buffered and reported later upon enabling the domain). + */ + void expectConsoleApiCallBuffered(Matcher paramsMatcher) { + if (!runtimeEnabled_) { + expectedConsoleApiCalls_.emplace_back(paramsMatcher); + } + } + bool isRuntimeDomainEnabled() const { return runtimeEnabled_; } @@ -758,6 +784,19 @@ TEST_P(ConsoleApiTest, testConsoleLogTwice) { eval("console.log('hello again');"); } +TEST_P(ConsoleApiTest, testConsoleLogWithObjectPreview) { + InSequence s; + expectConsoleApiCallImmediate(AllOf( + AtJsonPtr("/type", "log"), + AtJsonPtr("/args/0/preview/type", "object"), + AtJsonPtr("/args/0/preview/overflow", false), + AtJsonPtr("/args/0/preview/properties/0/name", "string"), + AtJsonPtr("/args/0/preview/properties/0/type", "string"), + AtJsonPtr("/args/0/preview/properties/0/value", "hello"))); + expectConsoleApiCallBuffered(AllOf(AtJsonPtr("/type", "log"))); + eval("console.log({ string: 'hello' });"); +} + static const auto paramValues = testing::Values( Params{ .withConsolePolyfill = true,