Repository: oppia/oppia

Issue:
Introduce the "as unknown as X" convention for testing and remove comments that explain it
To test some functionality in unit tests, we mock certain objects. The mock objects only have partial functionality when compared to the full object. This is because we only use certain methods or data from the object in the file we are testing. Mocking the full object is a waste of time and effort. However, the typescript strict checks will complain about this assignment. In order to get around this, we typecast the Mock to unknown and then to the type which we are mocking.

Tasks:
[ ] Modify the wiki to reflect this convention
[ ] Remove the explanation comments from codebase explaining the use of `as unknown as X` for mock Objects.


Discussion:

Resolving patch:
diff --git a/scripts/typescript_checks.py b/scripts/typescript_checks.py
--- a/scripts/typescript_checks.py
+++ b/scripts/typescript_checks.py
@@ -47,25 +47,16 @@
     'core/templates/App.ts',
     'core/templates/AppSpec.ts',
     'core/templates/Polyfills.ts',
-    'core/templates/app-events/event-bus.service.spec.ts',
     'core/templates/app.constants.ajs.ts',
-    'core/templates/components/button-directives/create-activity-button.component.spec.ts',
-    'core/templates/components/checkpoint-celebration-modal/checkpoint-celebration-modal.component.spec.ts',
     'core/templates/components/ck-editor-helpers/ck-editor-4-rte.component.ts',
     'core/templates/components/ck-editor-helpers/ck-editor-4-widgets.initializer.ts',
-    'core/templates/components/ck-editor-helpers/ck-editor-copy-toolbar/ck-editor-copy-toolbar.module.ts',
-    'core/templates/components/code-mirror/codemirror-mergeview.component.spec.ts',
     'core/templates/components/common-layout-directives/common-elements/answer-content-modal.component.spec.ts',
     'core/templates/components/common-layout-directives/common-elements/confirm-or-cancel-modal.controller.spec.ts',
-    'core/templates/components/common-layout-directives/common-elements/confirm-or-cancel-modal.controller.ts',
-    'core/templates/components/entity-creation-services/collection-creation.service.spec.ts',
     'core/templates/components/entity-creation-services/story-creation.service.spec.ts',
     'core/templates/components/entity-creation-services/story-creation.service.ts',
     'core/templates/components/forms/custom-forms-directives/apply-validation.directive.ts',
-    'core/templates/components/forms/custom-forms-directives/image-uploader.component.spec.ts',
     'core/templates/components/forms/custom-forms-directives/object-editor.directive.ts',
     'core/templates/components/forms/validators/is-float.filter.spec.ts',
-    'core/templates/components/forms/validators/is-float.filter.ts',
     'core/templates/components/forms/validators/schema-validators.spec.ts',
     'core/templates/components/interaction-display/interaction-display.component.spec.ts',
     'core/templates/components/interaction-display/interaction-display.component.ts',
@@ -83,65 +74,36 @@
     'core/templates/components/state-editor/state-editor.component.ts',
     'core/templates/components/state-editor/state-interaction-editor/state-interaction-editor.component.spec.ts',
     'core/templates/components/state-editor/state-interaction-editor/state-interaction-editor.component.ts',
-    'core/templates/directives/angular-html-bind.directive.ts',
     'core/templates/directives/mathjax-bind.directive.ts',
     'core/templates/domain/editor/undo_redo/undo-redo.service.spec.ts',
-    'core/templates/domain/email-dashboard/email-dashboard-backend-api.service.ts',
     'core/templates/domain/exploration/StatesObjectFactorySpec.ts',
     'core/templates/domain/exploration/editable-exploration-backend-api.service.spec.ts',
     'core/templates/domain/question/QuestionObjectFactorySpec.ts',
     'core/templates/domain/question/editable-question-backend-api.service.spec.ts',
     'core/templates/domain/question/question-update.service.spec.ts',
     'core/templates/domain/question/question-update.service.ts',
-    'core/templates/domain/recommendations/exploration-recommendations-backend-api.service.ts',
     'core/templates/domain/statistics/learner-answer-info.model.ts',
     'core/templates/domain/topic/topic-update.service.spec.ts',
     'core/templates/domain/topic/topic-update.service.ts',
-    'core/templates/domain/utilities/browser-checker.service.spec.ts',
-    'core/templates/filters/convert-html-to-unicode.filter.spec.ts',
-    'core/templates/filters/string-utility-filters/capitalize.filter.spec.ts',
-    'core/templates/filters/string-utility-filters/capitalize.filter.ts',
-    'core/templates/filters/string-utility-filters/convert-to-plain-text.filter.spec.ts',
-    'core/templates/filters/string-utility-filters/convert-to-plain-text.filter.ts',
     'core/templates/filters/truncate-input-based-on-interaction-answer-type.pipe.spec.ts',
     'core/templates/filters/truncate-input-based-on-interaction-answer-type.pipe.ts',
     'core/templates/karma.module.ts',
     'core/templates/pages/Base.ts',
-    'core/templates/pages/admin-page/activities-tab/admin-dev-mode-activities-tab.component.spec.ts',
     'core/templates/pages/admin-page/admin-blog-admin-common.module.ts',
     'core/templates/pages/admin-page/admin-page.import.ts',
-    'core/templates/pages/admin-page/features-tab/admin-features-tab.component.spec.ts',
-    'core/templates/pages/blog-admin-page/blog-admin-page.import.ts',
-    'core/templates/pages/blog-dashboard-page/blog-dashboard-page.import.ts',
     'core/templates/pages/blog-dashboard-page/shared-blog-components.module.ts',
     'core/templates/pages/classroom-page/classroom-page.module.ts',
-    'core/templates/pages/collection-editor-page/collection-editor-page.import.ts',
     'core/templates/pages/collection-editor-page/editor-tab/collection-node-creator.component.ts',
     'core/templates/pages/collection-player-page/collection-player-page.component.spec.ts',
     'core/templates/pages/collection-player-page/collection-player-page.component.ts',
     'core/templates/pages/collection-player-page/collection-player-page.import.ts',
     'core/templates/pages/contributor-dashboard-admin-page/contributor-dashboard-admin-page.component.spec.ts',
     'core/templates/pages/contributor-dashboard-admin-page/contributor-dashboard-admin-page.component.ts',
-    'core/templates/pages/contributor-dashboard-admin-page/contributor-dashboard-admin-page.import.ts',
-    'core/templates/pages/contributor-dashboard-admin-page/services/contributor-dashboard-admin-backend-api.service.ts',
     'core/templates/pages/contributor-dashboard-page/contributions-and-review/contributions-and-review.component.spec.ts',
     'core/templates/pages/contributor-dashboard-page/contributions-and-review/contributions-and-review.component.ts',
     'core/templates/pages/contributor-dashboard-page/contributor-dashboard-page.constants.ajs.spec.ts',
     'core/templates/pages/contributor-dashboard-page/contributor-dashboard-page.import.ts',
-    'core/templates/pages/contributor-dashboard-page/login-required-message/login-required-message.component.spec.ts',
-    'core/templates/pages/contributor-dashboard-page/modal-templates/question-suggestion-editor-modal.component.spec.ts',
-    'core/templates/pages/contributor-dashboard-page/modal-templates/question-suggestion-editor-modal.component.ts',
-    'core/templates/pages/contributor-dashboard-page/modal-templates/question-suggestion-review-modal.component.spec.ts',
-    'core/templates/pages/contributor-dashboard-page/modal-templates/question-suggestion-review-modal.component.ts',
-    'core/templates/pages/contributor-dashboard-page/modal-templates/translation-modal.component.spec.ts',
-    'core/templates/pages/contributor-dashboard-page/modal-templates/translation-modal.component.ts',
-    'core/templates/pages/contributor-dashboard-page/question-opportunities/question-opportunities.component.spec.ts',
-    'core/templates/pages/contributor-dashboard-page/question-opportunities/question-opportunities.component.ts',
-    'core/templates/pages/contributor-dashboard-page/services/contribution-and-review-backend-api.service.ts',
-    'core/templates/pages/contributor-dashboard-page/services/contribution-opportunities-backend-api.service.ts',
-    'core/templates/pages/contributor-dashboard-page/services/translate-text.service.spec.ts',
     'core/templates/pages/contributor-dashboard-page/services/translate-text.service.ts',
-    'core/templates/pages/creator-dashboard-page/creator-dashboard-page.component.spec.ts',
     'core/templates/pages/creator-dashboard-page/creator-dashboard-page.import.ts',
     'core/templates/pages/exploration-editor-page/editor-tab/exploration-editor-tab.component.spec.ts',
     'core/templates/pages/exploration-editor-page/editor-tab/exploration-editor-tab.component.ts',
@@ -180,7 +142,6 @@
     'core/templates/pages/exploration-player-page/learner-experience/conversation-skin.component.spec.ts',
     'core/templates/pages/exploration-player-page/learner-experience/conversation-skin.component.ts',
     'core/templates/pages/exploration-player-page/services/answer-classification.service.spec.ts',
-    'core/templates/pages/exploration-player-page/services/answer-classification.service.ts',
     'core/templates/pages/exploration-player-page/services/exploration-engine.service.spec.ts',
     'core/templates/pages/exploration-player-page/services/exploration-engine.service.ts',
     'core/templates/pages/exploration-player-page/services/exploration-player-state.service.ts',
@@ -193,10 +154,8 @@
     'core/templates/pages/learner-group-pages/edit-group/edit-learner-group-page.import.ts',
     'core/templates/pages/learner-group-pages/shared-learner-group-component.module.ts',
     'core/templates/pages/learner-group-pages/view-group/view-learner-group-page.import.ts',
-    'core/templates/pages/library-page/library-page.component.spec.ts',
     'core/templates/pages/library-page/search-bar/search-bar.component.spec.ts',
     'core/templates/pages/oppia-root/app-error-handler.ts',
-    'core/templates/pages/oppia-root/app.module.ts',
     'core/templates/pages/oppia-root/routing/app.routing.module.ts',
     'core/templates/pages/practice-session-page/practice-session-page.import.ts',
     'core/templates/pages/review-test-page/review-test-page.import.ts',
@@ -214,9 +173,6 @@
     'core/templates/pages/story-editor-page/story-editor-page.component.spec.ts',
     'core/templates/pages/story-editor-page/story-editor-page.component.ts',
     'core/templates/pages/story-editor-page/story-editor-page.import.ts',
-    'core/templates/pages/story-editor-page/story-preview-tab/story-preview-tab.component.spec.ts',
-    'core/templates/pages/story-viewer-page/story-viewer-page.component.spec.ts',
-    'core/templates/pages/subtopic-viewer-page/subtopic-viewer-page.import.ts',
     'core/templates/pages/topic-editor-page/editor-tab/topic-editor-stories-list.component.spec.ts',
     'core/templates/pages/topic-editor-page/editor-tab/topic-editor-stories-list.component.ts',
     'core/templates/pages/topic-editor-page/editor-tab/topic-editor-tab.directive.spec.ts',
@@ -235,10 +191,6 @@
     'core/templates/pages/topics-and-skills-dashboard-page/topics-and-skills-dashboard-page.import.ts',
     'core/templates/services/UpgradedServices.ts',
     'core/templates/services/angular-services.index.ts',
-    'core/templates/services/autogenerated-audio-player.service.spec.ts',
-    'core/templates/services/contextual/device-info.service.spec.ts',
-    'core/templates/services/contextual/url.service.spec.ts',
-    'core/templates/services/contextual/window-dimensions.service.spec.ts',
     'core/templates/services/exploration-improvements-task-registry.service.ts',
     'core/templates/services/nested-directives-recursion-timeout-prevention.service.spec.ts',
     'core/templates/services/nested-directives-recursion-timeout-prevention.service.ts',
@@ -249,37 +201,6 @@
     'core/templates/services/rte-helper.service.spec.ts',
     'core/templates/services/rte-helper.service.ts',
     'core/templates/services/translation-file-hash-loader-backend-api.service.ts',
-    'core/templates/components/question-directives/question-misconception-editor/question-misconception-editor.component.spec.ts',
-    'core/templates/components/summary-tile/exploration-summary-tile.component.spec.ts',
-    'core/templates/filters/truncate-input-based-on-interaction-answer-type.pipe.ts',
-    'core/templates/pages/contributor-dashboard-page/contributor-dashboard-page.component.spec.ts',
-    'core/templates/pages/contributor-dashboard-page/services/contribution-and-review-backend-api.service.ts',
-    'core/templates/pages/contributor-dashboard-page/services/contribution-opportunities-backend-api.service.ts',
-    'core/templates/pages/exploration-editor-page/editor-tab/services/responses.service.ts',
-    'core/templates/pages/exploration-editor-page/editor-tab/templates/modal-templates/teach-oppia-modal.component.spec.ts',
-    'core/templates/pages/exploration-editor-page/editor-tab/training-panel/training-modal.component.ts',
-    'core/templates/pages/exploration-editor-page/modal-templates/save-validation-fail-modal.component.spec.ts',
-    'core/templates/pages/exploration-editor-page/modal-templates/save-version-mismatch-modal.component.spec.ts',
-    'core/templates/pages/exploration-editor-page/services/exploration-objective.service.ts',
-    'core/templates/pages/exploration-editor-page/services/exploration-states.service.ts',
-    'core/templates/pages/exploration-editor-page/services/exploration-title.service.ts',
-    'core/templates/pages/exploration-editor-page/services/router.service.ts',
-    'core/templates/pages/exploration-editor-page/settings-tab/settings-tab.component.spec.ts',
-    'core/templates/pages/exploration-editor-page/statistics-tab/charts/pie-chart.component.spec.ts',
-    'core/templates/pages/exploration-editor-page/translation-tab/translation-tab.component.spec.ts',
-    'core/templates/pages/exploration-player-page/learner-experience/ratings-and-recommendations.component.spec.ts',
-    'core/templates/pages/exploration-player-page/learner-experience/tutor-card.component.spec.ts',
-    'core/templates/pages/exploration-player-page/services/answer-classification.service.ts',
-    'core/templates/pages/exploration-player-page/services/exploration-engine.service.ts',
-    'core/templates/pages/exploration-player-page/services/exploration-player-state.service.ts',
-    'core/templates/pages/exploration-player-page/services/question-player-engine.service.ts',
-    'core/templates/pages/participation-playbook/playbook.component.spec.ts',
-    'core/templates/pages/story-editor-page/services/story-editor-navigation.service.spec.ts',
-    'core/templates/services/guppy-configuration.service.spec.ts',
-    'core/templates/services/guppy-initialization.service.spec.ts',
-    'core/templates/services/keyboard-shortcut.service.spec.ts',
-    'core/templates/services/platform-feature.service.spec.ts',
-    'core/templates/services/prevent-page-unload-event.service.spec.ts',
     'core/templates/tests/unit-test-utils.ajs.ts',
     'core/tests/build_sources/templates/pages/Base.ts',
     'core/tests/karma.conf.ts',
@@ -296,7 +217,6 @@
     'extensions/interactions/GraphInput/directives/graph-viz.component.ts',
     'extensions/interactions/ImageClickInput/directives/oppia-interactive-image-click-input.component.spec.ts',
     'extensions/interactions/ImageClickInput/directives/oppia-interactive-image-click-input.component.ts',
-    'extensions/interactions/ItemSelectionInput/directives/oppia-interactive-item-selection-input.component.spec.ts',
     'extensions/interactions/ItemSelectionInput/item-selection-input-interactions.module.ts',
     'extensions/interactions/MultipleChoiceInput/directives/oppia-interactive-multiple-choice-input.component.spec.ts',
     'extensions/interactions/MultipleChoiceInput/directives/oppia-interactive-multiple-choice-input.component.ts',
@@ -308,10 +228,8 @@
     'extensions/interactions/PencilCodeEditor/directives/oppia-response-pencil-code-editor.component.ts',
     'extensions/interactions/PencilCodeEditor/directives/oppia-short-response-pencil-code-editor.component.ts',
     'extensions/interactions/base-validator.spec.ts',
-    'extensions/interactions/interaction-attributes-extractor.service.ts',
     'extensions/interactions/rules.spec.ts',
     'extensions/objects/object-components.module.ts',
-    'extensions/objects/templates/coord-two-dim-editor.component.spec.ts',
     'extensions/objects/templates/graph-property-editor.component.spec.ts',
     'extensions/objects/templates/graph-property-editor.component.ts',
     'extensions/objects/templates/image-editor.component.spec.ts',


Test patch: