Tiny test library for your tiny library.
You can use npm or yarn to install it.
npm install gc-victor/t-t.git#master
Create your first test
test('should return success if true', () => {
expect(0).toBe(0);
});
1 - should return success if true
Expects to throw an error
test('should throw an error', () => {
expect(() => {
throw Error('This is an error');
}).throws(new Error('This is an error'));
});
2 - should throw an error
You can use expect
with toBe
or any of the NodeJS Asserts methods.
If your library contains browser code, you can mock the window with window
.
test('should mock window', () => {
window('document', { test: () => true });
expect(document.test()).toBe(true);
});
3 - should mock window
Test asynchronously
test('should work asynchronously', async () => {
const zero = await Promise.resolve(0);
expect(0).toBe(zero);
});
Finally, you can spy a method using spyOn
.
test('should spy a method', () => {
const test = {
execute: () => 't-t'
};
const spy = spyOn(test, 'execute');
test.execute('test');
test.execute('test');
expect(spy).toBe({
args: ['test', 'test'],
count: 2,
output: 't-t'
});
});
4 - should spy a method
If you need to execute only one test from a list of tests, there is a simple trick for it.
import { test as t } from 't-t';
const only = t;
const test = () => {};
Enjoy :)
- AbdulFattah Popoola for the spyOn
- Kent C. Dodds for some ideas from his course
Given a version number MAJOR.MINOR, increment the:
- MAJOR version when you make backwards-incompatible updates of any kind
- MINOR version when you make 100% backwards-compatible updates
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR format.
First off, thanks for taking the time to contribute! Now, take a moment to be sure your contributions make sense to everyone else.
Found a problem? Want a new feature? First of all, see if your issue or idea has already been reported. If it hasn't, just open a new clear and descriptive issue.
A specification for adding human and machine readable meaning to commit messages.
Pull requests are the greatest contributions, so be sure they are focused in scope and do avoid unrelated commits.
- Fork it!
- Clone your fork:
git clone http://github.com/<your-username>/t-t
- Navigate to the newly cloned directory:
cd t-t
- Create a new branch for the new feature:
git checkout -b my-new-feature
- Install the tools necessary for development:
npm install
- Make your changes.
npm run build
to verify your change doesn't increase output size.npm test
to make sure your change doesn't break anything.- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request with full remarks documenting your changes.