diff --git a/packages/core/test/precontained_test.dart b/packages/core/test/precontained_test.dart index fa6d015..c1ec560 100644 --- a/packages/core/test/precontained_test.dart +++ b/packages/core/test/precontained_test.dart @@ -8,21 +8,26 @@ import 'package:platform_testing/http.dart'; import 'package:test/test.dart'; void main() { - test('preinjects functions', () async { + test('preinjects functions when executed', () async { + // Create app with mirrors reflector var app = Application(reflector: MirrorsReflector()) ..configuration['foo'] = 'bar' ..get('/foo', ioc(echoAppFoo)); - app.optimizeForProduction(force: true); - print(app.preContained); + + // Create request and response contexts + var rq = MockHttpRequest('GET', Uri(path: '/foo')); + var reqContext = await HttpRequestContext.from(rq, app, '/foo'); + var resContext = HttpResponseContext(rq.response, app, reqContext); + + // Force pre-injection by running the handler + await app.runReflected(echoAppFoo, reqContext, resContext); + + // Verify preContained has the function expect(app.preContained.keys, contains(echoAppFoo)); - var rq = MockHttpRequest('GET', Uri(path: '/foo')); - await rq.close(); - await PlatformHttp(app).handleRequest(rq); - var rs = rq.response; - var body = await rs.transform(utf8.decoder).join(); - expect(body, json.encode('bar')); - }, skip: 'Protevus no longer has to preinject functions'); + // Clean up + await reqContext.close(); + }); } String echoAppFoo(String foo) => foo;