Search⌘ K
AI Features

Your First Test

Explore writing your first unit test with Jest in React. Understand how to create test suites and assertions then run tests using npm. Gain confidence in basic test-driven development practices.

We'll cover the following...

Writing a test

Time for your first test. Create a file called greeting.test.js:

// greeting.test.js
const greeting = guest => `Hello, ${guest}!`;

describe('greeting()', () => { // 1
  it('says hello', () => { // 2
    expect(greeting('Jest')).toBe('Hello, Jest!'); // 3
  });
});
  1. describe() declares a test suite, which is a grouping of tests. Its first argument is a name, and the second is a
...