Jest Testing Suite
Inland Empire Software Development (IESD) non-profit organization main site.
Jest will test all files under the ./tests
directory when running the default script yarn run test
.
To start writing your first test, you must create a test file under the ./tests
directory. The naming convention for tests in this project is purpose.test.js
. This makes it easier to find specific collections of tests.
Jest is a powerful testing framework, to get started you just need the very basics. The code below is sample code to get you started writing simple tests. You will see three keywords that will be used throughout the whole project, describe
,test
and expect
.
const sum = require('../src/utils/sample');
// sample test suite - (name, callback)
describe("sample tests", () => {
// sample test (name, callback)
test('sum should add all numbers', () => {
// expected result
expect(sum(1, 2, 3, 4)).toBe(10);
});
// sample test
test('sum should only add numbers', () => {
// expected result
expect(sum(1, 2, 3, 'g')).toBe(6);
});
});
This work is licensed under a GNU General Public License.