Appearance
Allure Jest reference
These are the functions that you can use to integrate your Jest tests with Allure.
Metadata
Assign a test's description, links and other metadata.
Title
allure.displayName(name: string): Promise<void>
Set the test's title.
js
it("Test Authentication", async () => {
await allure.displayName("Test Authentication");
// ...
});
Description
allure.description(markdown: string): Promise<void>
Set the test's description. Markdown formatting is allowed. Any HTML formatting, if present, will be stripped for security purposes.
js
it("Test Authentication", async () => {
await allure.description(
"This test attempts to log into the website using a login and a password. Fails if any error happens.\n\nNote that this test does not test 2-Factor Authentication.",
);
// ...
});
Owner
allure.owner(owner: string): Promise<void>
Set the test's owner.
js
it("Test Authentication", async () => {
await allure.owner("John Doe");
// ...
});
Tag
allure.tag(tag: string): Promise<void>
Set the test's tags.
js
it("Test Authentication", async () => {
await allure.tag("web interface");
await allure.tag("authentication");
// ...
});
Severity
allure.severity(severity: string): Promise<void>
Set the test's severity.
Allowed values are: “trivial”, “minor”, “normal”, “critical”, and “blocker”.
js
it("Test Authentication", async () => {
await allure.severity("critical");
// ...
});
Label
allure.label(name: string, value: string): Promise<void>
Set an arbitrary label for the test. This is the underlying implementation for a lot of Allure's other functions.
The first argument of the function is the label name. It can be any string.
You can call label()
multiple times to create an array of values under the given name.
js
it("Test Authentication", async () => {
await allure.label("my custom label", "value");
// ...
});
ID
allure.id(allureId: string): Promise<void>
Set the test's ID.
js
it("Test Authentication", async () => {
await allure.id("123");
// ...
});
Link
allure.link(url: string, name?: string, type?: string): Promise<void>
allure.issue(name: string, url: string): Promise<void>
allure.tms(name: string, url: string): Promise<void>
Add a link related to the test.
Based on the type
(which can be any string), Allure will try to load a corresponding link pattern to process the URL, as defined by the links
configuration option. If no pattern found for the given type, the URL is left unmodified.
The name
will be used as the link's text. If it is omitted, the unprocessed URL will be used instead.
For convenience, Allure provides two shorthand functions with pre-selected link types: issue
and tms
.
js
it("Test Authentication", async () => {
await allure.link("https://dev.example.com/", "Website");
await allure.issue("AUTH-123", "AUTH-123");
await allure.tms("TMS-456", "TMS-456");
// ...
});
Behavior-based hierarchy
allure.epic(epic: string): Promise<void>
allure.feature(feature: string): Promise<void>
allure.story(story: string): Promise<void>
Assign names of epics, features or user stories for a test, as part of Allure's behavior-based hierarchy.
js
it("Test Authentication", async () => {
await allure.epic("Web interface");
await allure.feature("Essential features");
await allure.story("Authentication");
// ...
});
Suite-based hierarchy
allure.parentSuite(name: string): Promise<void>
allure.suite(name: string): Promise<void>
allure.subSuite(name: string): Promise<void>
Assign the name of suite, as part of Allure's suite-based hierarchy.
js
it("Test Authentication", async () => {
await allure.parentSuite("Tests for web interface");
await allure.suite("Tests for essential features");
await allure.subSuite("Tests for authentication");
// ...
});
Test steps
allure.step(name: string, body: (step?: AllureCommandStepExecutable) => void): Promise<void>
Define a test sub-step with the given name
.
The step()
function is asynchronous, and it accepts an asynchronous anonymous function as its second argument. Notice the async
and await
keywords in the example below.
If the step body is implemented as an arrow function with an argument, Allure Jest will pass an AllureCommandStepExecutable
object to it. You can use the object to create sub-steps or add attachments on the step level. If the step body is a traditional function and does not accept any arguments, the same features are available via this
.
js
it("Test Authentication", async () => {
await allure.step("Step 1", async (s1) => {
await s1.step("Sub-step 1", async (s1_1) => {
// ...
});
await s1.step("Sub-step 2", async (s1_2) => {
// ...
});
});
await allure.step("Step 2", async (step2) => {
// ...
});
});
js
it("Test Authentication", async () => {
await allure.step("Step 1", async function () {
await this.step("Sub-step 1", async function () {
// ...
});
await this.step("Sub-step 2", async function () {
// ...
});
});
await allure.step("Step 2", async function () {
// ...
});
});
Parametrized tests
allure.parameter(name: string, value: any, options?: ParameterOptions): Promise<void>
Specify a name
and value
of a parameter that was used during this test. See Parametrized tests for more details.
The options
argument, if given, must be an object with two optional properties excluded
and mode
.
If
excluded
is set to true, Allure will not use the parameter when comparing the current test result with previous one in the history. This argument is only used by Allure TestOps.The
mode
affects how the parameter will be displayed in the report. Available options are:"default"
(same as not specifying any mode) — the parameter and its value will be shown in a table along with other parameters."masked"
— the parameter will be shown in the table, but its value will be hidden. Use this mode for passwords, tokens and other sensitive parameters."hidden"
— the parameter and its value will not be shown in the test report. Note, however, that it is still possible to extract the value from theallure_results
directory if you publish it.
js
for (const login of ["johndoe", "[email protected]"]) {
it(`Test Authentication as ${login}`, async () => {
await allure.parameter("login", login);
await allure.parameter("time", new Date().toUTCString(), { excluded: true });
// ...
});
}
Attachments
attachment(content: string | Buffer, type: string, name?: string): Promise<void>
Add content
as an attachment to the test result. The content can be a text string or a base64-encoded Buffer
. You can use data produced by any function, not necessarily read from an actual file.
To ensure that the reader's web browser will display attachments correctly, specify each attachment's type. To do so, pass the media type of the content as type
.
The optional name
argument will be used as the filename if a user downloads the attachment from the test report.
js
const fs = require("fs");
it("Test Authentication", async () => {
// ...
await allure.attachment("This is the file content.", "text/plain", "Text file");
await allure.attachment(fs.readFileSync("/path/to/image.png"), "image/png", "Screenshot");
});