Compare commits
No commits in common. "master" and "v1.4.6" have entirely different histories.
4 changed files with 1 additions and 46 deletions
|
@ -111,11 +111,9 @@ $ eltro --watch my_watch_name --npm build
|
|||
|
||||
Not only does eltro allow you to use any assertion library of your own choosing, it also comes with it's own assertion library based on node's default [assert](https://nodejs.org/api/assert.html) with a few extra methods:
|
||||
|
||||
* `assert.equalWithMargin(value, test, margin, [message])`: Check if number value is equal to test with error margin.
|
||||
* `assert.notOk(value, [message])`: Assert value is not ok.
|
||||
* `assert.match(value, test, [message])`: Check if value matches RegExp test.
|
||||
* `assert.notMatch(value, [message])`: Check if value does not match RegExp test.
|
||||
* `assert.throwsAndCatch(fn, [message])`: Checks if function fn throws and returns the thrown error.
|
||||
* `assert.isFulfilled(promise, [message])`: Assert the promise resolves.
|
||||
* `assert.isRejected(promise, [message])`: Assert the promise gets rejects.
|
||||
|
||||
|
|
|
@ -57,14 +57,6 @@ assert.throwsAndCatch = (fn, message) => {
|
|||
return err
|
||||
}
|
||||
|
||||
assert.equalWithMargin = (value, test, margin = 0.005, message) => {
|
||||
assert.strictEqual(typeof value, 'number', 'Value should be number')
|
||||
assert.strictEqual(typeof test, 'number', 'Test should be number')
|
||||
|
||||
let difference = Math.abs(value - test)
|
||||
assert.ok(difference <= margin, message || `${value} ± ${margin} != ${test} (difference of ${difference} > ${margin})`)
|
||||
}
|
||||
|
||||
assert.isFulfilled = (promise, message) => {
|
||||
return Promise.resolve(true)
|
||||
.then(() => promise)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eltro",
|
||||
"version": "1.5.0",
|
||||
"version": "1.4.6",
|
||||
"description": "Eltro is a tiny no-dependancy test framework for node",
|
||||
"main": "index.mjs",
|
||||
"scripts": {
|
||||
|
|
|
@ -29,41 +29,6 @@ t.describe('#notOk()', function() {
|
|||
})
|
||||
})
|
||||
|
||||
t.describe('#equalWithMargin()', function() {
|
||||
t.test('should support default margin for floating point math', function() {
|
||||
let check = 0.1 + 0.2
|
||||
|
||||
assertExtended.throws(function() {
|
||||
assertExtended.strictEqual(check, 0.3)
|
||||
}, assertExtended.AssertionError)
|
||||
|
||||
assertExtended.equalWithMargin(check, 0.3)
|
||||
})
|
||||
|
||||
t.test('should support custom margin', function() {
|
||||
assertExtended.equalWithMargin(1, 2, 1)
|
||||
})
|
||||
|
||||
t.test('should fail if margin is too small', function() {
|
||||
assertExtended.throws(function() {
|
||||
assertExtended.equalWithMargin(1, 2, 0.9)
|
||||
}, assertExtended.AssertionError)
|
||||
})
|
||||
|
||||
t.test('should support custom message', function () {
|
||||
const assertMessage = 'Hello world'
|
||||
let error = null
|
||||
|
||||
try {
|
||||
assertExtended.equalWithMargin(1, 2, 0, assertMessage)
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
assert.ok(error)
|
||||
assert.match(error.message, new RegExp(assertMessage))
|
||||
})
|
||||
})
|
||||
|
||||
t.describe('#throwAndCatch()', function() {
|
||||
t.test('should work and return the original error', function() {
|
||||
const assertError = new Error('Speed')
|
||||
|
|
Loading…
Reference in a new issue