Skip to main content

Getting started

Overview

XBell is a modern web testing framework that combines unit testing with end-to-end testing.

You can freely switch between Node.js and Browser environments to test your code in one case.

Installation

$ npm install xbell

# install browser
$ npx xbell install browser

$ npx xbell

Writing Tests

Way 1: Node.js Testing

Test the code in nodejs

test-nodejs.test.js
import { test, expect } from 'xbell';
// import to nodejs
import { add } from './add';

test('test the code in nodejs', () => {
expect(add(1, 1)).toBe(2);
});

Way 2: Browser Testing

Test the code in browser

test-browser.test.js
import { test } from 'xbell';

test.browser('test the code in browser', async ({ expect }) => {
// 1. import to browser
const { add } = await import('./add');
// 2. expect in browser
expect(add(1, 1)).toBe(2);
});

Way 3: Nodejs & Browser

You can even run some code in NodeJS and some in the browser in just one case.

Alternatively, you can run the code in browser, make assertions in nodejs.

import { test } from 'xbell';

test('test the code in browser', async ({ page }) => {
// browser page
await page.evalute(async () => {
// 1. import to browser
const { add } = await import('./add');
// 2. render to browser
document.body.innerHTML = `<div>result is ${result}</div>`;
});

// 3. assetion in nodejs
await expect(page).toMatchSnapShot({
name: 'result-screenshot'
});
});