Search⌘ K
AI Features

Writing a Sample Test

Explore how to write your first JavaScript unit test using Jasmine with ES6 syntax. Understand the roles of describe, it, and expect blocks, and learn how to run tests using Karma and yarn to validate your code effectively.

Jasmine first test with Karma

This first test is just here to introduce Jasmine and Karma, not to be any useful test. This is Jasmine, using ES6 syntax, mostly the arrows:

C++
describe("JavaScript testing", () => {
it("works", () => {
expect(1 + 1).toEqual(2)
})
})

Jasmine’s syntax

  • Jasmine’s syntax is heavily inspired by RSpec, with JavaScript function objects taking Ruby blocks. Like RSpec test suites, Jasmine test suites start with describe. In Jasmine, describe is a
...