Testing - screenly/chrome-extension

Testing is an essential part of developing any software, including Chrome extensions. There are different ways to test a Chrome extension, and this document will cover some of the possible options using the project screenly/chrome-extension.

Unit Testing with Mocha and Chai

The project uses Mocha and Chai for unit testing. Mocha is a feature-rich JavaScript test framework running on Node.js, and Chai is a BDD / TDD assertion library for Node.js and the browser.

To run the unit tests, use the following command in the project directory:

$ npm test

This command runs all the tests in the src/test/spec directory using the test runner defined in the package.json file.

Here’s an example of a test file src/test/spec/example.spec.js:

const assert = require('chai').assert;
const example = require('../src/example');

describe('Example', () => {
it('should return the correct value', () => {
const result = example.add(1, 2);
assert.equal(result, 3);
});
});