Skip to main content

Test

test

test is the most basic tool method in XBell for declaring and writing test case.

Signature: test(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
import { test } from 'xbell';

test('goto github', async ({ page }) => {
await page.goto('https://github.com');
});

test.extend

Signature: test.extend(extendFunction)

  • extendFunction <(testArgs: TestArguments) => any>

test.extend can extend or customize the environment of the case, which will be executed before each case begins.

import { test as baisc } from 'xbell';

const test = basic.extend(({ expect }) => {
const data = [ 1, 2, 3, ];
return {
expect,
data,
};
});

test('extend demo', ({ expect, data }) => {
expect(data[0]).toBe(1);
});

test.each

Signature: test.each(items)(displayName, testFunction)

  • items <T[]>
  • displayName <(item: T) => string> case name
  • testFunction <(args: TestArguments & { item: T }) => void | Promise<void> > test function

Generate multiple test cases.

import { test } from 'xbell';

test.each([1, 2, 3])(
(item, index) => `case data is ${item}, index is ${index}`,
({ expect, item }) => {
expect(item).toBe(index + 1);
}
);

test.batch

Signature: test.batch(items)(displayName, testFunction)

  • items <T[]>
  • displayName <string> case name
  • testFunction <(args: TestArguments & { item: T }) => void | Promise<void> > test function

Unlike test.each , test.batch only generates one test case, so if one item fails, this test case will fail.

import { test } from 'xbell';

test.batch([1, 2, 3])(
'item is equal to the index plus one',
({ expect, item }) => {
expect(item).toBe(index + 1);
}
);

test.todo

Signature: test.todo(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
test.todo('goto github', async (page) => {
await page.goto('https://github.com');
});

test.only

Signature: test.only(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
test.only('goto github', async (page) => {
await page.goto('https://github.com');
});

test.skip

Signature: test.skip(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
test.skip('goto github', async (page) => {
await page.goto('https://github.com');
});

test.browser

Signature: test.browser(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
import { test } from 'xbell';

test.browser('one plus one equals two', async ({ page, expect }) => {
const { add } = await import('./add.ts');
expect(add(1, 1)).toBe(2);
});

test.browser.extend

Signature: test.browser.extend(extendFunction)

  • extendFunction <(testArgs: BrowserTestArguments) => any>

test.browser.extend can extend or customize the environment of the browser case, which will be executed before each case begins.

import { test as baisc } from 'xbell';

const test = basic.browser.extend(({ expect }) => {
const data = [ 1, 2, 3, ];

window.data = data;

return {
expect,
data,
};
});

test('browser extend demo', ({ expect, data }) => {
expect(data).toBe(window.data);
});

test.browser.each

Signature: test.browser.each(items)(displayName, testFunction)

  • items <T[]>
  • displayName <(item: T) => string> case name
  • testFunction <(args: TestArguments & { item: T }) => void | Promise<void> > test function

Generate multiple test cases.

import { test } from 'xbell';

test.browser.each([1, 2, 3])(
(item, index) => `case data is ${item}, index is ${index}`,
({ expect, item }) => {
expect(item).toBe(index + 1);
}
);

test.browser.batch

Signature: test.browser.batch(items)(displayName, testFunction)

  • items <T[]>
  • displayName <string> case name
  • testFunction <(args: TestArguments & { item: T }) => void | Promise<void> > test function

Unlike test.each , test.batch only generates one test case, so if one item fails, this test case will fail.

import { test } from 'xbell';

test.browser.batch([1, 2, 3])(
'item is equal to the index plus one',
({ expect, item }) => {
expect(item).toBe(index + 1);
}
);

test.browser.todo

Signature: test.browser.todo(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
test.browser.todo('goto github', async (page) => {
await page.goto('https://github.com');
});

test.browser.only

Signature: test.browser.only(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
test.browser.only('goto github', async (page) => {
await page.goto('https://github.com');
});

test.browser.skip

Signature: test.browser.skip(displayName, testFunction)

  • displayName <string> case name
  • testFunction <(args: TestArguments) => void | Promise<void> > test function
test.browser.skip('goto github', async (page) => {
await page.goto('https://github.com');
});

describe

Signature: describe(description, testGroupFunction)

  • description : <string>
  • testGroupFunction : <() => void;>

describe.skip

Signature: describe.skip(description, testGroupFunction)

  • description : <string>
  • testGroupFunction : <() => void;>

describe.only

Signature: describe.only(description, testGroupFunction)

  • description : <string>
  • testGroupFunction : <() => void;>

describe.todo

Signature: describe.todo(description, testGroupFunction)

  • description : <string>
  • testGroupFunction : <() => void;>