This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Core): correctly treat optional pipe dependencies as optional
Previously the `@Optional()` annotation used to mark injected dependencies as optional was ignored on pipes, meaning a "No provider found ..." error would be thrown when attempting to instantiate a pipe with a missing optional dependency. Fixes #1665. PiperOrigin-RevId: 222314430
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
_tests/test/regression/1665_optional_pipe_dependency_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@TestOn('browser') | ||
import 'package:test/test.dart'; | ||
import 'package:angular/angular.dart'; | ||
import 'package:angular_test/angular_test.dart'; | ||
|
||
import '1665_optional_pipe_dependency_test.template.dart' as ng; | ||
|
||
void main() { | ||
tearDown(disposeAnyRunningTest); | ||
|
||
test('a missing @Optional() pipe dependency does not throw', () async { | ||
var testBed = NgTestBed.forComponent(ng.TestComponentNgFactory); | ||
expect(testBed.create(), completes); | ||
}); | ||
} | ||
|
||
abstract class TestService {} | ||
|
||
@Pipe('test') | ||
class TestPipe { | ||
TestPipe(@Optional() TestService _); | ||
|
||
dynamic transform(dynamic value) => value; | ||
} | ||
|
||
@Component( | ||
selector: 'test', | ||
template: '{{value | test}}', | ||
pipes: [TestPipe], | ||
) | ||
class TestComponent { | ||
var value = 'Hello world!'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters