https://github.com/shaack/teevi
Allows unit testing of ES6 modules without additional dependencies right in your browser.
https://github.com/shaack/teevi
Last synced: over 1 year ago
JSON representation
Allows unit testing of ES6 modules without additional dependencies right in your browser.
- Host: GitHub
- URL: https://github.com/shaack/teevi
- Owner: shaack
- License: mit
- Created: 2017-11-29T12:54:40.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-09T18:48:36.000Z (about 3 years ago)
- Last Synced: 2025-03-08T10:51:58.124Z (over 1 year ago)
- Language: JavaScript
- Size: 46.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Teevi
Tired of installing 1000 dependencies, just to run unit tests? Teevi is
the essence of unit testing in JavaScript.
It allows unit testing of JS without additional dependencies, right in your browser.
Teevi has almost the same syntax as Mocha with Chai but is a hundred times smaller.
Demo: [http://shaack.com/projekte/teevi/test/](http://shaack.com/projekte/teevi/test/)
## Usage
1. Create the test script `MyTest.js`
```javascript
import {describe, it, assert} from "../src/teevi.js";
describe("Teevi test demo", () => {
it("will not fail", () => {
assert.true(2 * 2 === 4)
})
it("will fail", () => {
assert.equals(4 + 2, 42)
})
})
```
2. Create a `test/index.html` to run the tests in your browser
```html
Tests
import {teevi} from "./src/teevi.js"
import "./MyTest.js"
teevi.run()
```

## it.only
Use `it.only(condition, testMethod)` to run only these tests in your test module.
## possible assertions
- `assert.fail(message = DEFAULT_MESSAGE)`
- `assert.true(message = DEFAULT_MESSAGE)`
- `assert.false(message = DEFAULT_MESSAGE)`
- `equal(actual, expected, message = DEFAULT_MESSAGE)`
- `notEqual(actual, notExpected, message = DEFAULT_MESSAGE)`
- use `reject(message)` from an async `Promise` (see example below)
## Testing async calls
You can also test async calls, with the use of promises.
```javascript
it("should test async", () => {
return new Promise((resolve) => {
setTimeout(() => {
// `resolve`, if test succeeds
resolve()
}, 500)
})
})
it("should fail async", () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
// in Promises use `reject()`, not `assert`
reject("failed, because of testing")
}, 500)
})
})
```