test: Add unit tests for stringHelper.contains and randomAlphanumeric - #1173
Open
olitreadwell wants to merge 2 commits into
Open
test: Add unit tests for stringHelper.contains and randomAlphanumeric#1173olitreadwell wants to merge 2 commits into
olitreadwell wants to merge 2 commits into
Conversation
The stringHelper.contains method had no test coverage. The other four methods in string.js are tested, but contains was skipped, and the source file has a TODO to update its unit tests. This adds a test that covers the true case (a substring is present), the false case (no substring matches), and the empty-list edge case.
The other five methods in string.js are tested, but randomAlphanumeric had no test coverage. This adds a test that checks the return value is a non-empty string and that two calls produce different values.
Closed
4 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changed
Adds unit tests for two uncovered helpers in
common/components/utils/string.js, both incommon/components/test/string.test.js:contains: one test, four assertions (true case, false case, empty-list edge case).randomAlphanumeric: one test, three assertions (returns a string, returns a non-empty string, returns a different value across calls).No source code changed.
Why
common/components/utils/string.jsexports six static helpers.The existing test file covered four of them (
isEmptyOrWhitespace,trimStartString,startsWithAny,isValidSlug) but notcontainsorrandomAlphanumeric.The source file also carries a
// TODO: Update unit testscomment.So both helpers had zero coverage.
These tests lock in their behaviour.
How to verify
Expected: 6 passed (was 4 before this change).
Coverage
N/A: the repo has no coverage tool wired up.
Method-level:
containsandrandomAlphanumericgo from 0 tests to 1 each.Checks run locally
npx prettier --checkclean on the changed file)