codex-lv3-may-2025

Level Navigation: 1 (2ℹ️) 3 4 5 6 (7ℹ️) (8ℹ️) (9ℹ️) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 (37ℹ️) 38⚡ 39⚡ 40⚡ 41⚡ 42 43⚡ 44⚡ 45 46 (47ℹ️)

Level 25: Make the Test Pass (Green) - Exclamation Marks

Now let’s fix it by adding a replaceAll() call for exclamation marks:

export function toSnakeCase(text) {
  return text.replaceAll(' ', '_').replaceAll('!', '_').toLowerCase();
}

What does this do?

Oops! We broke our old test!

When we add this feature to convert ! to _, we’re changing how our function works. Remember that test we wrote back in a previous level? It’s going to fail now!

In a previous level, we had a test that expected:

it('should handle text with special characters', () => {
  const result = toSnakeCase('Hello World!');
  expect(result).toBe('hello_world!'); // This expects the ! to be preserved
});

But now our function converts ! to _, so the result will be 'hello_world_' instead of 'hello_world!'.

Sometimes we need to change our tests! When we intentionally change how a function works, we need to update our tests to match the new behavior. Go back to that previous test and update it to expect 'hello_world_' instead of 'hello_world!'.

Try it now:

  1. Update your toSnakeCase function with the new feature
  2. Update that previous test to expect 'hello_world_' instead of 'hello_world!' or just remove it.
  3. Run your tests again. Both the new test and the updated test from the previous level should pass (green)!