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 24: Write a Failing Test for Exclamation Marks (Red)

Let’s say we want our toSnakeCase function to also replace exclamation marks with underscores. Currently, our function only handles spaces:

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

Let’s write a test that we know will fail because the function doesn’t handle exclamation marks yet:

it('should replace exclamation marks with underscores', () => {
  const result = toSnakeCase('Hello World!');
  expect(result).toBe('hello_world_');
});

Try it now: Add this test to your toSnakeCase tests and run it. What happens?

You should see a red (failing) test! The test expects 'hello_world_' but gets 'hello_world!' because the function only replaces spaces, not exclamation marks.