Skip to content

Commit 73f8d88

Browse files
committed
Add missing reporting tests for template reference variable
1 parent 0b7066c commit 73f8d88

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/rules/eslint-plugin-angular-template-consistent-this.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,82 @@ test {{
881881
.`,
882882
}),
883883

884+
/**
885+
* Template *reference* variable (`#template`) accessed via databinding.
886+
*/
887+
convertAnnotatedSourceToFailureCase({
888+
description:
889+
"it fails with implicit template reference variable via databinding where it should be explicit.",
890+
annotatedSource: `\
891+
<test-elm-with-id #test_identifier>
892+
<test-elm-child [prop]="test_identifier.property"></test-elm-child>
893+
~~~~~~~~~~~~~~~
894+
</test-elm-with-id>`,
895+
options: [{ templateReferences: "explicit" }],
896+
messageId: MESSAGE_IDS.templateReferences.explicit,
897+
data: { prop: "test_identifier" },
898+
annotatedOutput: `\
899+
<test-elm-with-id #test_identifier>
900+
<test-elm-child [prop]="this.test_identifier.property"></test-elm-child>
901+
902+
</test-elm-with-id>`,
903+
}),
904+
convertAnnotatedSourceToFailureCase({
905+
description:
906+
"it fails with explicit template reference variable via databinding where it should be implicit.",
907+
annotatedSource: `\
908+
<test-elm-with-id #test_identifier>
909+
<test-elm-child [prop]="this.test_identifier.property"></test-elm-child>
910+
~~~~~~~~~~~~~~~~~~~~
911+
</test-elm-with-id>`,
912+
options: [{ templateReferences: "implicit" }],
913+
messageId: MESSAGE_IDS.templateReferences.implicit,
914+
data: { prop: "test_identifier" },
915+
annotatedOutput: `\
916+
<test-elm-with-id #test_identifier>
917+
<test-elm-child [prop]="test_identifier.property"></test-elm-child>
918+
919+
</test-elm-with-id>`,
920+
}),
921+
922+
/**
923+
* Template *reference* variable (`#template`) accessed via interpolation.
924+
*/
925+
convertAnnotatedSourceToFailureCase({
926+
description:
927+
"it fails with implicit template reference variable via interpolation where it should be explicit.",
928+
annotatedSource: `\
929+
<test-elm-with-id #test_identifier>
930+
{{ test_identifier.property }}
931+
~~~~~~~~~~~~~~~
932+
</test-elm-with-id>`,
933+
options: [{ templateReferences: "explicit" }],
934+
messageId: MESSAGE_IDS.templateReferences.explicit,
935+
data: { prop: "test_identifier" },
936+
annotatedOutput: `\
937+
<test-elm-with-id #test_identifier>
938+
{{ this.test_identifier.property }}
939+
940+
</test-elm-with-id>`,
941+
}),
942+
convertAnnotatedSourceToFailureCase({
943+
description:
944+
"it fails with explicit template reference variable via interpolation where it should be implicit.",
945+
annotatedSource: `\
946+
<test-elm-with-id #test_identifier>
947+
{{ this.test_identifier.property }}
948+
~~~~~~~~~~~~~~~~~~~~
949+
</test-elm-with-id>`,
950+
options: [{ templateReferences: "implicit" }],
951+
messageId: MESSAGE_IDS.templateReferences.implicit,
952+
data: { prop: "test_identifier" },
953+
annotatedOutput: `\
954+
<test-elm-with-id #test_identifier>
955+
{{ test_identifier.property }}
956+
957+
</test-elm-with-id>`,
958+
}),
959+
884960
/**
885961
* NgIf directive `*ngIf` with "as variable" and then & else
886962
* references to templates that are defined *after* property reading.

0 commit comments

Comments
 (0)