Repository navigation
fix(curriculum): accept valid enums in digital pet game tests - #71496
Closed
jerome-queck wants to merge 2 commits into
Closed
jerome-queck wants to merge 2 commits into
jerome-queck wants to merge 2 commits into
Conversation
Aryan9891
reviewed
Nov 1, 2026
Aryan9891
left a comment
There was a problem hiding this comment.
Technical Code Review & Static Analysis
This is a great fix for the regex character-class pitfall and alignment between user stories and test assertions in the Digital Pet Game lab.
Code Analysis & Verification:
-
Regex Fix on Character Classes:
- The previous test used
/\s*enum\s+PetMood\s*{[\s*\w+,\s*]*HAPPY[\s*\w+,\s*]*}/. Because[\s*\w+,\s*]is a regex character class (bracket expression), characters like*,+, and,were evaluated as literal single characters rather than repetition operators. As a result, valid TypeScript enums with string initializers (HAPPY = "happy") or comments immediately failed the test. - Refactoring to
assert.match(__helpers.removeJSComments(code), /\benum\s+PetMood\s*\{[^}]*\bHAPPY\b[^}]*\}/)is much cleaner.[^}]*safely scopes the match to the enum body, while the word boundaries\bHAPPY\bprevent false-positive prefix/suffix substring collisions.
- The previous test used
-
Whitespace Flexibility on Record Types:
- Updating the Record test to
/\b(?:const|let|var)\s+\w+\s*:\s*Record\s*<\s*PetMood\s*,\s*string\s*>/properly accommodates arbitrary valid whitespace around colons and generic type arguments without failing standard code formatters.
- Updating the Record test to
-
Curriculum Consistency:
- Synchronizing the User Stories from PascalCase (
Happy,Excited, etc.) to uppercase (HAPPY,EXCITED, etc.) removes the discrepancy between the challenge requirements and the test assertions. - Corrected the stray quote in the
SADhint and the unclosed bracket in theRecorddescription.
- Synchronizing the User Stories from PascalCase (
All changes are strictly aligned with freeCodeCamp curriculum guidelines and automated test helpers.
The PetMood member checks used a character class, so string initializers and comments failed. Match the enum body after stripping comments, accept a Record annotation without requiring a space after the colon, and align the user stories with the uppercase member names.
jerome-queck
force-pushed
the
fix/digital-pet-mood-tests
branch
from
November 2, 2026 14:36
4e5e099 to
dd410d9
Compare
godsgiftjhon167-code
left a comment
There was a problem hiding this comment.
"Look good thank for fixing the regex."
Member
|
Hi there, thank you for your interest in contributing. However, the linked issue hasn't been triaged yet, so I'm closing this PR to keep the queue manageable. Feel free to open a new PR once consensus has been reached and the issue is marked as ready for contribution. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist:
mainbranch of freeCodeCamp.Closes #71494
The Digital Pet Game tests for
PetMoodmembers used/enum\s+PetMood\s*{[\s*\w+,\s*]*HAPPY[\s*\w+,\s*]*}/. Those brackets are a character class, so a valid enum with initializers (HAPPY = "happy") or a comment in the body failed every member test.Comments are removed first, then each member is matched inside the enum body, so initializers, comments, and spacing are accepted. The
Record<PetMood, string>test no longer requires a space after the colon (const moods:Record<PetMood, string>passes).The user stories now use the same uppercase member names as the tests and the reference solution. The
SADhint no longer has a stray quote, and the Record hint includes the closing>.