Skip to content

Core Methods

For testing, Latte provides a set of core methods that are essential for writing and executing tests. These methods are designed to be simple and intuitive, allowing developers to focus on writing effective tests without getting bogged down in complex syntax.

describe(), suite()

These methods are used to group related tests to the test suite. It takes a string as the first argument, which serves as the name of the test suite, and a callback function as the second argument, which contains the individual test cases.

describe(`Common tests suite`, () => {
it(...)
...
it(...)
})
suite(`Common tests suite`, () => {
it(...)
...
it(...)
})

it()

This method is used to define a single test case in the suite. It takes a string as the first argument, which serves as the name of the test, and a callback function as the second argument, which contains the actual test logic.

function hello() {
return `Hello`
}
describe(`Common tests suite`, () => {
it(`says hello`, () => {
expect(hello()).toBe(`Hello`)
})
})

test()

This method is used to create a standalone test case. It is similar to it, but used outside a describe or suite blocks.

function hello() {
return `Hello`
}
test(`says hello`, () => {
expect(hello()).toBe(`Hello`)
})

expect()

This method is used to create an expectation for a value. It takes a value as its argument and returns an object with various matchers that can be used to assert conditions about the value.

expect(value).toBe(expectedValue)

Setup and Teardown

These methods are used to setup and teardown test environments. It allows you to run code before or after each test case or test suite. For more information, see Setup and Teardown.