Skip to content

fix(curriculum): accept valid enums in digital pet game tests - #71496

Closed
jerome-queck wants to merge 2 commits into
freeCodeCamp:mainfrom
jerome-queck:fix/digital-pet-mood-tests
Closed

jerome-queck wants to merge 2 commits into
freeCodeCamp:mainfrom
jerome-queck:fix/digital-pet-mood-tests

Conversation

@jerome-queck

Copy link
Copy Markdown
Contributor

Checklist:

Closes #71494

The Digital Pet Game tests for PetMood members 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 SAD hint no longer has a stray quote, and the Record hint includes the closing >.

@jerome-queck
jerome-queck requested a review from a team as a code owner October 31, 2026 14:59
@github-actions github-actions Bot added the scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. label Oct 31, 2026

@Aryan9891 Aryan9891 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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\b prevent false-positive prefix/suffix substring collisions.
  2. 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.
  3. 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 SAD hint and the unclosed bracket in the Record description.

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
jerome-queck force-pushed the fix/digital-pet-mood-tests branch from 4e5e099 to dd410d9 Compare November 2, 2026 14:36
@majestic-owl448 majestic-owl448 added the frontend libraries v9 cert This is for the issues dealing with the Frontend Libraries V9 Certification. label Nov 13, 2026

@godsgiftjhon167-code godsgiftjhon167-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Look good thank for fixing the regex."

@huyenltnguyen

Copy link
Copy Markdown
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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frontend libraries v9 cert This is for the issues dealing with the Frontend Libraries V9 Certification. scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Digital Pet Game lab: PetMood enum and Record tests reject valid TypeScript

5 participants