assertron 9.0.8 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -57
- package/cjs/assert-order/AssertOrder.js +169 -98
- package/cjs/assert-order/AssertOrder.js.map +1 -0
- package/cjs/assert-order/InvalidOrder.js +37 -8
- package/cjs/assert-order/InvalidOrder.js.map +1 -0
- package/cjs/assert-order/StateMachine.js +147 -57
- package/cjs/assert-order/StateMachine.js.map +1 -0
- package/cjs/assert-order/index.js +18 -5
- package/cjs/assert-order/index.js.map +1 -0
- package/cjs/assert-order/types.js +1 -1
- package/cjs/assert-order/types.js.map +1 -0
- package/cjs/assertron/assertron.js +21 -21
- package/cjs/assertron/assertron.js.map +1 -0
- package/cjs/assertron/falsy.js +3 -3
- package/cjs/assertron/falsy.js.map +1 -0
- package/cjs/assertron/index.js +16 -3
- package/cjs/assertron/index.js.map +1 -0
- package/cjs/assertron/pathEqual.js +4 -4
- package/cjs/assertron/pathEqual.js.map +1 -0
- package/cjs/assertron/rejects.js +4 -4
- package/cjs/assertron/rejects.js.map +1 -0
- package/cjs/assertron/repeat.js +9 -7
- package/cjs/assertron/repeat.js.map +1 -0
- package/cjs/assertron/resolves.js +4 -4
- package/cjs/assertron/resolves.js.map +1 -0
- package/cjs/assertron/satisfies.js +4 -4
- package/cjs/assertron/satisfies.js.map +1 -0
- package/cjs/assertron/throws.js +13 -11
- package/cjs/assertron/throws.js.map +1 -0
- package/cjs/assertron/truthy.js +3 -3
- package/cjs/assertron/truthy.js.map +1 -0
- package/cjs/errors.js +32 -8
- package/cjs/errors.js.map +1 -0
- package/cjs/index.js +22 -7
- package/cjs/index.js.map +1 -0
- package/cjs/types.js +1 -1
- package/cjs/types.js.map +1 -0
- package/cjs/utils/index.js +21 -8
- package/cjs/utils/index.js.map +1 -0
- package/cjs/utils/isErrorConstructor.js +1 -1
- package/cjs/utils/isErrorConstructor.js.map +1 -0
- package/cjs/utils/notEqualMessage.js +1 -1
- package/cjs/utils/notEqualMessage.js.map +1 -0
- package/cjs/utils/notSatisfiedMessage.js +11 -3
- package/cjs/utils/notSatisfiedMessage.js.map +1 -0
- package/cjs/utils/notThrownMessage.js +1 -1
- package/cjs/utils/notThrownMessage.js.map +1 -0
- package/cjs/utils/promiseMessages.js +1 -1
- package/cjs/utils/promiseMessages.js.map +1 -0
- package/cjs/utils/unexpectedErrorMessage.js +3 -3
- package/cjs/utils/unexpectedErrorMessage.js.map +1 -0
- package/esm/assert-order/AssertOrder.js +9 -3
- package/esm/assert-order/AssertOrder.js.map +1 -0
- package/esm/assert-order/InvalidOrder.js +20 -5
- package/esm/assert-order/InvalidOrder.js.map +1 -0
- package/esm/assert-order/StateMachine.js +37 -4
- package/esm/assert-order/StateMachine.js.map +1 -0
- package/esm/assert-order/index.js +4 -4
- package/esm/assert-order/index.js.map +1 -0
- package/esm/assert-order/types.js +1 -1
- package/esm/assert-order/types.js.map +1 -0
- package/esm/assertron/assertron.js +11 -11
- package/esm/assertron/assertron.js.map +1 -0
- package/esm/assertron/falsy.js +2 -2
- package/esm/assertron/falsy.js.map +1 -0
- package/esm/assertron/index.js +2 -2
- package/esm/assertron/index.js.map +1 -0
- package/esm/assertron/pathEqual.js +3 -3
- package/esm/assertron/pathEqual.js.map +1 -0
- package/esm/assertron/rejects.js +4 -4
- package/esm/assertron/rejects.js.map +1 -0
- package/esm/assertron/repeat.js +2 -2
- package/esm/assertron/repeat.js.map +1 -0
- package/esm/assertron/resolves.js +3 -3
- package/esm/assertron/resolves.js.map +1 -0
- package/esm/assertron/satisfies.js +3 -3
- package/esm/assertron/satisfies.js.map +1 -0
- package/esm/assertron/throws.js +3 -3
- package/esm/assertron/throws.js.map +1 -0
- package/esm/assertron/truthy.js +2 -2
- package/esm/assertron/truthy.js.map +1 -0
- package/esm/errors.js +14 -4
- package/esm/errors.js.map +1 -0
- package/esm/index.js +6 -5
- package/esm/index.js.map +1 -0
- package/esm/types.js +1 -1
- package/esm/types.js.map +1 -0
- package/esm/utils/index.js +7 -7
- package/esm/utils/index.js.map +1 -0
- package/esm/utils/isErrorConstructor.js +1 -1
- package/esm/utils/isErrorConstructor.js.map +1 -0
- package/esm/utils/notEqualMessage.js +1 -1
- package/esm/utils/notEqualMessage.js.map +1 -0
- package/esm/utils/notSatisfiedMessage.js +1 -1
- package/esm/utils/notSatisfiedMessage.js.map +1 -0
- package/esm/utils/notThrownMessage.js +1 -1
- package/esm/utils/notThrownMessage.js.map +1 -0
- package/esm/utils/promiseMessages.js +1 -1
- package/esm/utils/promiseMessages.js.map +1 -0
- package/esm/utils/unexpectedErrorMessage.js +2 -2
- package/esm/utils/unexpectedErrorMessage.js.map +1 -0
- package/package.json +48 -46
- package/{src → ts}/assert-order/AssertOrder.ts +2 -2
- package/{src → ts}/assert-order/InvalidOrder.ts +2 -2
- package/{src → ts}/assert-order/StateMachine.ts +1 -1
- package/ts/assert-order/index.ts +4 -0
- package/{src → ts}/assert-order/internalInterfaces.ts +0 -0
- package/{src → ts}/assert-order/types.ts +0 -0
- package/ts/assertron/assertron.ts +29 -0
- package/{src → ts}/assertron/falsy.ts +1 -1
- package/ts/assertron/index.ts +1 -0
- package/{src → ts}/assertron/pathEqual.ts +2 -2
- package/{src → ts}/assertron/rejects.ts +3 -3
- package/{src → ts}/assertron/repeat.ts +2 -2
- package/{src → ts}/assertron/resolves.ts +2 -2
- package/{src → ts}/assertron/satisfies.ts +2 -2
- package/{src → ts}/assertron/throws.ts +5 -5
- package/{src → ts}/assertron/truthy.ts +1 -1
- package/{src → ts}/errors.ts +1 -1
- package/ts/index.ts +7 -0
- package/{src → ts}/testUtils.ts +3 -3
- package/{src → ts}/types.ts +0 -0
- package/ts/utils/index.ts +12 -0
- package/{src → ts}/utils/isErrorConstructor.ts +1 -1
- package/{src → ts}/utils/notEqualMessage.ts +0 -1
- package/{src → ts}/utils/notSatisfiedMessage.ts +2 -2
- package/{src → ts}/utils/notThrownMessage.ts +0 -0
- package/{src → ts}/utils/promiseMessages.ts +0 -0
- package/{src → ts}/utils/unexpectedErrorMessage.ts +3 -3
- package/cjs/assert-order/AssertOrder.d.ts +0 -41
- package/cjs/assert-order/AssertOrder.d.ts.map +0 -1
- package/cjs/assert-order/InvalidOrder.d.ts +0 -9
- package/cjs/assert-order/InvalidOrder.d.ts.map +0 -1
- package/cjs/assert-order/StateMachine.d.ts +0 -22
- package/cjs/assert-order/StateMachine.d.ts.map +0 -1
- package/cjs/assert-order/index.d.ts +0 -4
- package/cjs/assert-order/index.d.ts.map +0 -1
- package/cjs/assert-order/types.d.ts +0 -8
- package/cjs/assert-order/types.d.ts.map +0 -1
- package/cjs/assertron/assertron.d.ts +0 -21
- package/cjs/assertron/assertron.d.ts.map +0 -1
- package/cjs/assertron/falsy.d.ts +0 -2
- package/cjs/assertron/falsy.d.ts.map +0 -1
- package/cjs/assertron/index.d.ts +0 -2
- package/cjs/assertron/index.d.ts.map +0 -1
- package/cjs/assertron/pathEqual.d.ts +0 -2
- package/cjs/assertron/pathEqual.d.ts.map +0 -1
- package/cjs/assertron/rejects.d.ts +0 -2
- package/cjs/assertron/rejects.d.ts.map +0 -1
- package/cjs/assertron/repeat.d.ts +0 -6
- package/cjs/assertron/repeat.d.ts.map +0 -1
- package/cjs/assertron/resolves.d.ts +0 -2
- package/cjs/assertron/resolves.d.ts.map +0 -1
- package/cjs/assertron/satisfies.d.ts +0 -10
- package/cjs/assertron/satisfies.d.ts.map +0 -1
- package/cjs/assertron/throws.d.ts +0 -6
- package/cjs/assertron/throws.d.ts.map +0 -1
- package/cjs/assertron/truthy.d.ts +0 -2
- package/cjs/assertron/truthy.d.ts.map +0 -1
- package/cjs/errors.d.ts +0 -17
- package/cjs/errors.d.ts.map +0 -1
- package/cjs/index.d.ts +0 -6
- package/cjs/index.d.ts.map +0 -1
- package/cjs/tsconfig.cjs.tsbuildinfo +0 -1
- package/cjs/types.d.ts +0 -3
- package/cjs/types.d.ts.map +0 -1
- package/cjs/utils/index.d.ts +0 -8
- package/cjs/utils/index.d.ts.map +0 -1
- package/cjs/utils/isErrorConstructor.d.ts +0 -3
- package/cjs/utils/isErrorConstructor.d.ts.map +0 -1
- package/cjs/utils/notEqualMessage.d.ts +0 -2
- package/cjs/utils/notEqualMessage.d.ts.map +0 -1
- package/cjs/utils/notSatisfiedMessage.d.ts +0 -3
- package/cjs/utils/notSatisfiedMessage.d.ts.map +0 -1
- package/cjs/utils/notThrownMessage.d.ts +0 -2
- package/cjs/utils/notThrownMessage.d.ts.map +0 -1
- package/cjs/utils/promiseMessages.d.ts +0 -3
- package/cjs/utils/promiseMessages.d.ts.map +0 -1
- package/cjs/utils/unexpectedErrorMessage.d.ts +0 -3
- package/cjs/utils/unexpectedErrorMessage.d.ts.map +0 -1
- package/esm/tsconfig.esm.tsbuildinfo +0 -1
- package/src/assert-order/AssertOrder.spec.ts +0 -446
- package/src/assert-order/InvalidOrder.spec.ts +0 -60
- package/src/assert-order/index.ts +0 -4
- package/src/assertron/assertron.spec.ts +0 -40
- package/src/assertron/assertron.ts +0 -29
- package/src/assertron/falsy.spec.ts +0 -20
- package/src/assertron/index.ts +0 -1
- package/src/assertron/pathEqual.spec.ts +0 -28
- package/src/assertron/rejects.spec.ts +0 -32
- package/src/assertron/repeat.spec.ts +0 -47
- package/src/assertron/resolves.spec.ts +0 -29
- package/src/assertron/satisfies.spec.ts +0 -159
- package/src/assertron/throws.spec.ts +0 -184
- package/src/assertron/truthy.spec.ts +0 -23
- package/src/index.ts +0 -6
- package/src/utils/index.ts +0 -12
- package/src/utils/notSatisfiedMessage.spec.ts +0 -31
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AssertionError } from '../errors'
|
|
2
|
-
import { notEqualMessage } from '../utils'
|
|
3
|
-
import { falsy } from './falsy'
|
|
4
|
-
import { pathEqual } from './pathEqual'
|
|
5
|
-
import { rejects } from './rejects'
|
|
6
|
-
import { repeat } from './repeat'
|
|
7
|
-
import { resolves } from './resolves'
|
|
8
|
-
import { satisfies } from './satisfies'
|
|
9
|
-
import { throws } from './throws'
|
|
10
|
-
import { truthy } from './truthy'
|
|
11
|
-
|
|
12
|
-
export const assertron = {
|
|
13
|
-
false(value: any) {
|
|
14
|
-
if (value !== false)
|
|
15
|
-
throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
|
|
16
|
-
},
|
|
17
|
-
falsy,
|
|
18
|
-
pathEqual,
|
|
19
|
-
rejects,
|
|
20
|
-
repeat,
|
|
21
|
-
resolves,
|
|
22
|
-
satisfies,
|
|
23
|
-
throws,
|
|
24
|
-
true(value: any) {
|
|
25
|
-
if (value !== true)
|
|
26
|
-
throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
|
|
27
|
-
},
|
|
28
|
-
truthy
|
|
29
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import a, { AssertionError } from '..'
|
|
2
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
3
|
-
|
|
4
|
-
test('non-false statement throws', () => {
|
|
5
|
-
assertThrows(() => a.falsy(true), AssertionError)
|
|
6
|
-
assertThrows(() => a.falsy(1 === 1), AssertionError)
|
|
7
|
-
assertThrows(() => a.falsy(1), AssertionError)
|
|
8
|
-
assertThrows(() => a.falsy({}), AssertionError)
|
|
9
|
-
assertThrows(() => a.falsy(() => true), AssertionError)
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('does not contain internal stack trace', () => {
|
|
13
|
-
const err = assertThrows(() => a.falsy(true), AssertionError)
|
|
14
|
-
noStackTraceFor('falsy.ts', err)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('false statement pass', () => {
|
|
18
|
-
a.falsy(false)
|
|
19
|
-
a.falsy(1 === 2 as any)
|
|
20
|
-
})
|
package/src/assertron/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './assertron'
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import assertron, { AssertionError } from '..'
|
|
2
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
3
|
-
|
|
4
|
-
test('path with same style passes', () => {
|
|
5
|
-
assertron.pathEqual('a', 'a')
|
|
6
|
-
assertron.pathEqual('a/b', 'a/b')
|
|
7
|
-
assertron.pathEqual('a\\b', 'a\\b')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test('same style different value throws', () => {
|
|
11
|
-
assertThrows(() => assertron.pathEqual('a', 'b'))
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('UNIX style matches Windows style', () => {
|
|
15
|
-
assertron.pathEqual('a/b', 'a\\b')
|
|
16
|
-
assertron.pathEqual('a/b/c', 'a\\b\\c')
|
|
17
|
-
assertron.pathEqual('a\\b', 'a/b')
|
|
18
|
-
assertron.pathEqual('a\\b\\c', 'a/b/c')
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
test(`/d/foo should match d:\\foo`, () => {
|
|
22
|
-
assertron.pathEqual('/d/foo', 'd:\\foo')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test('does not contain internal stack trace', () => {
|
|
26
|
-
const err = assertThrows(() => assertron.pathEqual('a', 'b'), AssertionError)
|
|
27
|
-
noStackTraceFor('pathEqual.ts', err)
|
|
28
|
-
})
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import t from 'assert'
|
|
2
|
-
import a from '..'
|
|
3
|
-
import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
|
|
4
|
-
|
|
5
|
-
test('pass on rejected promise', async () => {
|
|
6
|
-
await a.rejects(Promise.reject(1))
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
test('throws on resolved string promise', async () => {
|
|
10
|
-
const err = await a.throws(a.rejects(Promise.resolve('abc')))
|
|
11
|
-
t.strictEqual(err.message, `Expected promise to reject, but it resolves with 'abc'`)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('throws on resolved boolean promise', async () => {
|
|
15
|
-
const err = await a.throws(a.rejects(Promise.resolve(true)))
|
|
16
|
-
t.strictEqual(err.message, `Expected promise to reject, but it resolves with true`)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('throws on resolved object promise', async () => {
|
|
20
|
-
const err = await a.throws(a.rejects(Promise.resolve(2)))
|
|
21
|
-
t.strictEqual(err.message, `Expected promise to reject, but it resolves with 2`)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('throws on resolved object promise', async () => {
|
|
25
|
-
const err = await a.throws(a.rejects(Promise.resolve({ a: 1 })))
|
|
26
|
-
t.strictEqual(err.message, `Expected promise to reject, but it resolves with { a: 1 }`)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('does not contain internal stack trace', async () => {
|
|
30
|
-
const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 })))
|
|
31
|
-
noStackTraceFor('rejects.ts', err)
|
|
32
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import a, { FailOnOccurrence } from '..'
|
|
2
|
-
|
|
3
|
-
test('repeat function n times', () => {
|
|
4
|
-
let count = 0
|
|
5
|
-
a.repeat(() => ++count, 10)
|
|
6
|
-
|
|
7
|
-
expect(count).toBe(10)
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test('repeat async function n times sequentially', async () => {
|
|
11
|
-
let count = 0
|
|
12
|
-
let actual = ''
|
|
13
|
-
const aa = await a.repeat(() => new Promise<string>(a => {
|
|
14
|
-
setTimeout(() => {
|
|
15
|
-
++count
|
|
16
|
-
actual += String(count)
|
|
17
|
-
a(actual)
|
|
18
|
-
}, Math.random() * 10)
|
|
19
|
-
}), 10)
|
|
20
|
-
|
|
21
|
-
expect(actual).toBe('12345678910')
|
|
22
|
-
expect(actual).toBe(aa)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test('error is captured as inner error and indicate which call failed', () => {
|
|
26
|
-
let count = 0
|
|
27
|
-
const err = a.throws(() => a.repeat(() => {
|
|
28
|
-
if (++count === 5) throw new Error('failed')
|
|
29
|
-
}, 10), FailOnOccurrence)
|
|
30
|
-
|
|
31
|
-
expect(err.occurrence).toBe(5)
|
|
32
|
-
expect(err.error.message).toBe('failed')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('rejected error is captured as inner error and indicate which call failed', async () => {
|
|
36
|
-
let count = 0
|
|
37
|
-
const err = await a.throws(a.repeat(() => new Promise<void>((a, r) => {
|
|
38
|
-
setTimeout(() => {
|
|
39
|
-
++count
|
|
40
|
-
if (count === 5) r(new Error('failed'))
|
|
41
|
-
else a()
|
|
42
|
-
}, Math.random() * 10)
|
|
43
|
-
}), 10), FailOnOccurrence)
|
|
44
|
-
|
|
45
|
-
expect(err.occurrence).toBe(5)
|
|
46
|
-
expect(err.error.message).toBe('failed')
|
|
47
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import t from 'assert'
|
|
2
|
-
import a, { AssertionError } from '..'
|
|
3
|
-
import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
test('pass on resolved promise', async () => {
|
|
7
|
-
await a.resolves(Promise.resolve())
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test('throws on rejected string promise', async () => {
|
|
11
|
-
const err = await a.throws(a.resolves(Promise.reject('abc')), AssertionError)
|
|
12
|
-
t.strictEqual(err.message, `Expected promise to resolve, but it rejects with 'abc'`)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('throws on rejected error promise', async () => {
|
|
16
|
-
const err = await a.throws(a.resolves(Promise.reject(new Error('foo'))), AssertionError)
|
|
17
|
-
t.strictEqual(err.message, `Expected promise to resolve, but it rejects with Error: foo`)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('throws on rejected object promise', async () => {
|
|
21
|
-
const err = await a.throws(a.resolves(Promise.reject({ a: 1 })), AssertionError)
|
|
22
|
-
t.strictEqual(err.message, `Expected promise to resolve, but it rejects with { a: 1 }`)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test('does not contain internal stack trace', async () => {
|
|
26
|
-
const err = await assertAsyncThrows(() => a.resolves(Promise.reject({ a: 1 })), AssertionError)
|
|
27
|
-
noStackTraceFor('resolves.ts', err)
|
|
28
|
-
})
|
|
29
|
-
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { every, has, isInRange, some } from 'satisfier'
|
|
2
|
-
import { isType } from 'type-plus'
|
|
3
|
-
import a, { AssertionError } from '..'
|
|
4
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
5
|
-
|
|
6
|
-
describe('non-composable types', () => {
|
|
7
|
-
test('accept same type', () => {
|
|
8
|
-
a.satisfies(null, null)
|
|
9
|
-
a.satisfies(undefined, undefined)
|
|
10
|
-
a.satisfies(1, 1)
|
|
11
|
-
a.satisfies('a', 'a')
|
|
12
|
-
a.satisfies(true, true)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('predicate parameter is the widen type', () => {
|
|
16
|
-
a.satisfies(null, (v) => isType<null>(v))
|
|
17
|
-
a.satisfies(undefined, (v) => isType<undefined>(v))
|
|
18
|
-
a.satisfies(1, (v) => isType<number>(v))
|
|
19
|
-
a.satisfies('a', (v) => isType<string>(v))
|
|
20
|
-
a.satisfies(true, (v) => isType<boolean>(v))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('shows value directly in error', () => {
|
|
24
|
-
a.throws(() => a.satisfies(1, 2), e => e.message === 'Expect actual to satisfy 2, but received 1')
|
|
25
|
-
a.throws(() => a.satisfies(true, false), e => e.message === 'Expect actual to satisfy false, but received true')
|
|
26
|
-
a.throws(() => a.satisfies('a', 'b'), e => e.message === `Expect actual to satisfy 'b', but received 'a'`)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('use regex to check against string', () => {
|
|
30
|
-
a.satisfies('abc', /a/)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('empty object will pass any object', () => {
|
|
35
|
-
a.satisfies({}, {})
|
|
36
|
-
a.satisfies({ a: 1 }, {})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('empty object will fail against primitive types', () => {
|
|
40
|
-
a.throws(() => a.satisfies(1, {} as any), e => e.message === 'Expect actual to satisfy {}, but received 1')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
// test(`can use satisfier util function such as has()/every()`, () => {
|
|
44
|
-
// a.satisfies([1], every(1))
|
|
45
|
-
// a.throws(() => a.satisfies([1, 2], every(1)), e => e.message === 'Expect actual[1] to satisfy 1, but received 2')
|
|
46
|
-
// })
|
|
47
|
-
|
|
48
|
-
test(`array entries are checked`, () => {
|
|
49
|
-
a.throws(() => a.satisfies([1], [2]), e => e.message === `Expect actual[0] to satisfy 2, but received 1`)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('work with primitive array', () => {
|
|
53
|
-
a.satisfies([1, 2, 3], [1, 2, 3])
|
|
54
|
-
a.satisfies([true, false], [true, false])
|
|
55
|
-
a.satisfies(['a', 'b'], ['a', 'b'])
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test(`check deep entry in array`, () => {
|
|
59
|
-
a.throws(() => a.satisfies([1, { a: { b: 1 } }], [1, { a: { b: 2 } }]), e => e.message === `Expect actual[1].a.b to satisfy 2, but received 1`)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('missing property will fail', () => {
|
|
63
|
-
a.throws(() => a.satisfies({}, { a: 1 }), e => e.message === `Expect a to satisfy 1, but received undefined`)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('missing property at deeper level', () => {
|
|
67
|
-
a.throws(() => a.satisfies({ a: {} }, { a: { b: 1 } }), e => e.message === `Expect a.b to satisfy 1, but received undefined`)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
test('extra property will pass', () => {
|
|
71
|
-
a.satisfies({ a: 1, b: 2 }, { a: 1 })
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
test('property not match will fail', () => {
|
|
75
|
-
a.throws(() => a.satisfies({ a: 1 }, { a: 2 }), e => e.message === `Expect a to satisfy 2, but received 1`)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test('regex will match regex', () => {
|
|
79
|
-
a.satisfies({ a: /foo/ }, { a: /foo/ })
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('regex will be used to match', () => {
|
|
83
|
-
a.satisfies({ a: 'foo' }, { a: /foo/ })
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test('function will use as predicate', () => {
|
|
87
|
-
a.satisfies({ a: 1 }, { a: a => a === 1 })
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('predicate error should mention path', () => {
|
|
91
|
-
a.throws(() => a.satisfies({ a: 1 }, { a: () => false }), e => e.message === `Expect a to satisfy () => false, but received 1`)
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
test('deep predicate error should mention path', () => {
|
|
95
|
-
a.throws(() => a.satisfies({ a: { b: 1 } }, { a: { b: b => b === 2 } }), e => e.message === `Expect a.b to satisfy b => b === 2, but received 1`)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
test('can check parent property', () => {
|
|
99
|
-
class Foo {
|
|
100
|
-
foo = 'foo'
|
|
101
|
-
}
|
|
102
|
-
class Boo extends Foo {
|
|
103
|
-
boo = 'boo'
|
|
104
|
-
}
|
|
105
|
-
const boo = new Boo()
|
|
106
|
-
a.satisfies(boo, { foo: 'foo' })
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
test('actual of type any should not have type checking error', () => {
|
|
110
|
-
const actual: any = { a: 1 }
|
|
111
|
-
a.satisfies(actual, { a: 1 })
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
test('Work with null in array', () => {
|
|
115
|
-
interface Foo {
|
|
116
|
-
payload: any
|
|
117
|
-
}
|
|
118
|
-
const action: Foo = { payload: [null, 3, 4] }
|
|
119
|
-
a.satisfies(action, { payload: [null, 3, 4] })
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('does not contain internal stack trace', async () => {
|
|
123
|
-
const err = assertThrows(() => a.satisfies({ a: 1 }, { a: 2 }), AssertionError)
|
|
124
|
-
noStackTraceFor('satisfies.ts', err)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
test('allow partial expectation on array entries', () => {
|
|
128
|
-
type U = { type: 'a', a: string } | { type: 'b', b: string }
|
|
129
|
-
const x: U[] = [{ type: 'a', a: 'abc' }]
|
|
130
|
-
a.satisfies(x, [{ type: 'a' }])
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
test('allow predicate on array', () => {
|
|
134
|
-
type U = { type: 'a', a: string } | { type: 'b', b: string }
|
|
135
|
-
const x: U[] = [{ type: 'a', a: 'abc' }]
|
|
136
|
-
a.satisfies(x, (v) => v[0].type == 'a')
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
test('allow predicate on array entries', () => {
|
|
140
|
-
type U = { type: 'a', a: string } | { type: 'b', b: string }
|
|
141
|
-
const x: U[] = [{ type: 'a', a: 'abc' }]
|
|
142
|
-
a.satisfies(x, [(v) => v.type == 'a'])
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
test('using has()', () => {
|
|
146
|
-
a.satisfies([1, 2, 3], has(2))
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
test('using every()', () => {
|
|
150
|
-
a.satisfies([1, 2, 3], every((x: number) => x > 0))
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
test('using isInRange()', () => {
|
|
154
|
-
a.satisfies(1, isInRange(1, 3))
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
test('using some()', () => {
|
|
158
|
-
a.satisfies([1, 2, 3], some((x: number) => x % 2 === 0))
|
|
159
|
-
})
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import t from 'assert'
|
|
2
|
-
import a, { AssertionError } from '..'
|
|
3
|
-
import { assertAsyncThrows, assertIsError, assertIsPromise, assertThrows, noStackTraceFor } from '../testUtils'
|
|
4
|
-
|
|
5
|
-
test('when value is PromiseLike returns a promise with the rejected value', async () => {
|
|
6
|
-
let actual = a.throws(Promise.reject(new Error('Miku')), Error)
|
|
7
|
-
assertIsPromise(actual)
|
|
8
|
-
t.equal((await actual).message, 'Miku')
|
|
9
|
-
|
|
10
|
-
actual = a.throws(Promise.reject(new Error('Ren')), () => true)
|
|
11
|
-
assertIsPromise(actual)
|
|
12
|
-
t.equal((await actual).message, 'Ren')
|
|
13
|
-
|
|
14
|
-
actual = a.throws(Promise.reject(new Error('Luka')))
|
|
15
|
-
assertIsPromise(actual)
|
|
16
|
-
t.equal((await actual).message, 'Luka')
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('when value is function returning a promise, will return a promise with the rejected value', async () => {
|
|
20
|
-
let actual = a.throws(() => Promise.reject(new Error('Miku')), Error)
|
|
21
|
-
assertIsPromise(actual)
|
|
22
|
-
t.equal((await actual).message, 'Miku')
|
|
23
|
-
|
|
24
|
-
actual = a.throws(() => Promise.reject(new Error('Luka')), () => true)
|
|
25
|
-
assertIsPromise(actual)
|
|
26
|
-
t.equal((await actual).message, 'Luka')
|
|
27
|
-
|
|
28
|
-
actual = a.throws(() => Promise.reject('Ren'))
|
|
29
|
-
assertIsPromise(actual)
|
|
30
|
-
t.equal((await actual), 'Ren')
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
test('when value is function returns error', () => {
|
|
34
|
-
let actual = a.throws((() => { throw new Error() }), Error)
|
|
35
|
-
assertIsError(actual)
|
|
36
|
-
|
|
37
|
-
actual = a.throws((() => { throw new Error() }))
|
|
38
|
-
assertIsError(actual)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
test('throws if input is not a function or promise', () => {
|
|
42
|
-
assertThrows(() => a.throws(0 as any))
|
|
43
|
-
assertThrows(() => a.throws(true as any))
|
|
44
|
-
assertThrows(() => a.throws('...' as any))
|
|
45
|
-
assertThrows(() => a.throws(/foo/ as any))
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test('throws for resolved promise', () => {
|
|
49
|
-
return assertAsyncThrows(() => a.throws(Promise.resolve('ok')), AssertionError)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('throws error does not contain internal stack trace for resolved promise', async () => {
|
|
53
|
-
const err = await assertAsyncThrows(() => a.throws(Promise.resolve('ok')), AssertionError)
|
|
54
|
-
noStackTraceFor('throws.ts', err)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('passes with rejected promise', async () => {
|
|
58
|
-
const actual = await a.throws<string>(() => new Promise((_, r) => setImmediate(() => r('no'))))
|
|
59
|
-
t.strictEqual(actual, 'no')
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('passes with rejected promise passing validator', () => {
|
|
63
|
-
return a.throws(Promise.reject('no'), err => err === 'no')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('throws with rejected promise failing validator', async () => {
|
|
67
|
-
await assertAsyncThrows(
|
|
68
|
-
() => a.throws(Promise.reject('no'), err => err !== 'no'),
|
|
69
|
-
AssertionError)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test('thrown error does not contain internal stack trace with rejected promise failing validator', async () => {
|
|
73
|
-
const err = await assertAsyncThrows(() => a.throws(Promise.reject('no'), err => err !== 'no'), AssertionError)
|
|
74
|
-
// Error.captureStackTrace(err, a.throws)
|
|
75
|
-
|
|
76
|
-
noStackTraceFor('throws.ts', err)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('passes with throwing function', () => {
|
|
80
|
-
a.throws(() => { throw new Error('foo') })
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test('throws if function does not', () => {
|
|
84
|
-
assertThrows(
|
|
85
|
-
() => a.throws(() => { return 'foo' }, AssertionError),
|
|
86
|
-
AssertionError
|
|
87
|
-
)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('thrown error does not contain internal stack track if function does not', () => {
|
|
91
|
-
const err = assertThrows(
|
|
92
|
-
() => a.throws(() => { return 'foo' }, AssertionError),
|
|
93
|
-
AssertionError
|
|
94
|
-
)
|
|
95
|
-
noStackTraceFor('throws.ts', err)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
test('throws if function returns resolved promise', async () => {
|
|
99
|
-
await assertAsyncThrows(
|
|
100
|
-
() => a.throws(() => Promise.resolve('ok')),
|
|
101
|
-
AssertionError)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test('thrown error does not contain internal stack trace if function returns resolved promise', async () => {
|
|
105
|
-
const err = await assertAsyncThrows(
|
|
106
|
-
() => a.throws(() => Promise.resolve('ok')),
|
|
107
|
-
AssertionError)
|
|
108
|
-
noStackTraceFor('throws.ts', err)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('pass if function returns rejected promise', () => {
|
|
112
|
-
return a.throws(() => { return Promise.reject('ok') })
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test('pass if function returns rejected promise passing valdation', () => {
|
|
116
|
-
return a.throws(
|
|
117
|
-
() => { return Promise.reject('ok') },
|
|
118
|
-
err => err === 'ok')
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
test('throws if function returns rejected promise not passing valdation', async () => {
|
|
122
|
-
await assertAsyncThrows(
|
|
123
|
-
() => a.throws(() => Promise.reject('ok'), err => err !== 'ok'),
|
|
124
|
-
AssertionError
|
|
125
|
-
)
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
test('thrown error does not contain stack trace if function returns rejected promise not passing valdation', async () => {
|
|
129
|
-
const err = await assertAsyncThrows(
|
|
130
|
-
() => a.throws(() => Promise.reject('ok'), err => err !== 'ok'),
|
|
131
|
-
AssertionError
|
|
132
|
-
)
|
|
133
|
-
// console.log('got err', err)
|
|
134
|
-
noStackTraceFor('throws.ts', err)
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
class FakeError extends Error {
|
|
138
|
-
constructor(msg?: string) {
|
|
139
|
-
super(msg || 'some fake msg')
|
|
140
|
-
|
|
141
|
-
Object.setPrototypeOf(this, new.target.prototype)
|
|
142
|
-
}
|
|
143
|
-
foo = 'foo'
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
test('validate Promise using Error constructor', async () => {
|
|
147
|
-
const err = await a.throws(Promise.reject(new FakeError('abc')), FakeError)
|
|
148
|
-
t.strictEqual(err.foo, 'foo')
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
test('validate Promise using another Error constructor will throw', async () => {
|
|
152
|
-
const err = await assertAsyncThrows(() => a.throws(Promise.reject(new FakeError()), AssertionError), AssertionError)
|
|
153
|
-
|
|
154
|
-
t.strictEqual(err.message, `Unexpected error. Expecting 'AssertionError' but received FakeError('some fake msg')`)
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
test('validate () => Promise using Error constructor', async () => {
|
|
158
|
-
const err = await a.throws(() => Promise.reject(new FakeError()), FakeError)
|
|
159
|
-
t.strictEqual(err.foo, 'foo')
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
test('validate () => Promise using another Error constructor will throw', () => {
|
|
163
|
-
return assertAsyncThrows(() => a.throws(() => Promise.reject(new FakeError()), AssertionError))
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
test('validate () => throw using Error constructor', async () => {
|
|
167
|
-
const err = await a.throws((() => { throw new FakeError() }) as any, FakeError)
|
|
168
|
-
t.strictEqual(err.foo, 'foo')
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
test('validate () => throw using another Error constructor will throw', async () => {
|
|
172
|
-
return t.throws(() => a.throws((() => { throw new FakeError() }) as any, AssertionError))
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
test(`a.throws(() => never) returns error of type Error`, () => {
|
|
176
|
-
const err = a.throws(() => { throw new Error('failure') })
|
|
177
|
-
expect(err.message).toBe('failure')
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
test('throw if function returns an object', () => {
|
|
181
|
-
class Dummy { a = 1; foo() { } }
|
|
182
|
-
const err = assertThrows(() => a.throws(() => new Dummy()), AssertionError)
|
|
183
|
-
expect(err.message).toBe(`Expect function to throw, but it returned 'Dummy { a: 1 }' instead.`)
|
|
184
|
-
})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import a, { AssertionError } from '..'
|
|
2
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
3
|
-
|
|
4
|
-
test('falsy statement throws', () => {
|
|
5
|
-
assertThrows(() => a.truthy(false), AssertionError)
|
|
6
|
-
assertThrows(() => a.truthy(''), AssertionError)
|
|
7
|
-
assertThrows(() => a.truthy(0), AssertionError)
|
|
8
|
-
assertThrows(() => a.truthy(null), AssertionError)
|
|
9
|
-
assertThrows(() => a.truthy(undefined), AssertionError)
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('truthy statement pass', () => {
|
|
13
|
-
a.truthy(true)
|
|
14
|
-
a.truthy('a')
|
|
15
|
-
a.truthy(-1)
|
|
16
|
-
a.truthy({})
|
|
17
|
-
a.truthy(() => false)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('does not contain internal stack trace', () => {
|
|
21
|
-
const err = assertThrows(() => a.truthy(false), AssertionError)
|
|
22
|
-
noStackTraceFor('truthy.ts', err)
|
|
23
|
-
})
|
package/src/index.ts
DELETED
package/src/utils/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { tersify } from 'tersify';
|
|
2
|
-
|
|
3
|
-
export * from './isErrorConstructor';
|
|
4
|
-
export * from './notEqualMessage';
|
|
5
|
-
export * from './notSatisfiedMessage';
|
|
6
|
-
export * from './notThrownMessage';
|
|
7
|
-
export * from './promiseMessages';
|
|
8
|
-
export * from './unexpectedErrorMessage';
|
|
9
|
-
|
|
10
|
-
export function failOnOccurrence(occurrence: number, error: any) {
|
|
11
|
-
return `Failed on ${occurrence} occurrence: ${tersify(error, { maxLength: Infinity })}`
|
|
12
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import t from 'assert';
|
|
2
|
-
import { notSatisfiedMessage } from '.';
|
|
3
|
-
|
|
4
|
-
test('array should be tersified', () => {
|
|
5
|
-
|
|
6
|
-
t.strictEqual(notSatisfiedMessage([{
|
|
7
|
-
path: ['a'],
|
|
8
|
-
actual: {
|
|
9
|
-
a: [1, 2, 3]
|
|
10
|
-
},
|
|
11
|
-
expected: {
|
|
12
|
-
b: ['a', 'b', 'c']
|
|
13
|
-
}
|
|
14
|
-
}]), `Expect a to satisfy { b: ['a', 'b', 'c'] }, but received { a: [1, 2, 3] }`)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test(`root diff is displayed as 'actual'`, () => {
|
|
18
|
-
t.strictEqual(notSatisfiedMessage([{
|
|
19
|
-
path: [],
|
|
20
|
-
actual: 1,
|
|
21
|
-
expected: 2
|
|
22
|
-
}]), `Expect actual to satisfy 2, but received 1`)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test(`root diff is displayed as 'actual'`, () => {
|
|
26
|
-
t.strictEqual(notSatisfiedMessage([{
|
|
27
|
-
path: ['[0]'],
|
|
28
|
-
actual: 1,
|
|
29
|
-
expected: 2
|
|
30
|
-
}]), `Expect [0] to satisfy 2, but received 1`)
|
|
31
|
-
})
|