platform/packages/framework/test/precontained_test.dart

29 lines
915 B
Dart
Raw Normal View History

import 'dart:convert';
2021-05-14 10:34:09 +00:00
import 'package:angel3_container/mirrors.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'package:angel3_mock_request/angel3_mock_request.dart';
2020-02-05 23:02:46 +00:00
2017-06-06 12:42:33 +00:00
import 'package:test/test.dart';
2021-05-14 10:34:09 +00:00
void main() {
2017-06-06 12:42:33 +00:00
test('preinjects functions', () async {
2019-05-02 22:48:31 +00:00
var app = Angel(reflector: MirrorsReflector())
2017-09-24 19:43:14 +00:00
..configuration['foo'] = 'bar'
..get('/foo', ioc(echoAppFoo));
2017-06-06 12:42:33 +00:00
app.optimizeForProduction(force: true);
print(app.preContained);
2018-08-21 18:50:43 +00:00
expect(app.preContained.keys, contains(echoAppFoo));
2017-06-06 12:42:33 +00:00
2019-05-02 22:48:31 +00:00
var rq = MockHttpRequest('GET', Uri(path: '/foo'));
2020-02-05 23:02:46 +00:00
(rq.close());
2019-05-02 22:48:31 +00:00
await AngelHttp(app).handleRequest(rq);
2017-06-06 12:42:33 +00:00
var rs = rq.response;
2018-06-08 07:06:26 +00:00
var body = await rs.transform(utf8.decoder).join();
expect(body, json.encode('bar'));
2018-08-21 18:50:43 +00:00
}, skip: 'Angel no longer has to preinject functions');
2017-06-06 12:42:33 +00:00
}
echoAppFoo(String foo) => foo;