Repository navigation
Conversation
| test("should throw an error when passed a string", () => { | ||
| expect(() => | ||
| contains("sun", "a").toThrow(new Error("contains requires an object")) | ||
| ); | ||
| }); | ||
|
|
||
| test("should throw an error when passed a number", () => { | ||
| expect(() => | ||
| contains(9, "a").toThrow(new Error("contains requires an object")) | ||
| ); | ||
| }); | ||
|
|
||
| test("should throw an error when passed a null", () => { | ||
| expect(() => | ||
| contains("sun", null).toThrow(new Error("contains requires an object")) | ||
| ); | ||
| }); | ||
|
|
||
| test("should throw an error when passed no argument", () => { | ||
| expect(() => contains().toThrow(new Error("contains requires an object"))); | ||
| }); |
There was a problem hiding this comment.
The string, number, null, and missing-argument cases place .toThrow(...) inside the callback, so Jest never receives a toThrow assertion. The null case also passes a string as the object and null as the key.
To "like" or "dislike" this comment, please follow this link
|
The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look. |
| const decodeKey = decodeURIComponent(key.replace(/\+/g, " ")); | ||
| const decodeValue = decodeURIComponent(value.replace(/\+/g, " ")); |
There was a problem hiding this comment.
The regex works fine here. Can you think of something else that would be more readable for a reader who doesn’t want to decode the \+ and the g flag? Have a look at the string methods available on String.prototype and consider whether one of them would do the same job.
There was a problem hiding this comment.
could also use the replaceAll. like so:
const decodeKey = decodeURIComponent(key.replaceAll("+", " "));
const decodeValue = decodeURIComponent(value.replaceAll("+", " "));
There was a problem hiding this comment.
That’s correct, well done! replaceAll("+", " ") is easier to read than the regex. Nice that you applied it to both lines.
Task code
CYF-1083
Changelist