test: add service tests for DirectusClient, DirectusError, categories, files, listings, and notifications
This commit is contained in:
@@ -107,6 +107,52 @@ export function assertDeepEquals(actual, expected, message = '') {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert inequality
|
||||
* @param {*} actual
|
||||
* @param {*} expected
|
||||
* @param {string} [message]
|
||||
*/
|
||||
export function assertNotEquals(actual, expected, message = '') {
|
||||
if (actual === expected) {
|
||||
throw new Error(
|
||||
message || `Expected values to differ, but both are ${JSON.stringify(actual)}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const asyncQueue = []
|
||||
|
||||
/**
|
||||
* Define an async test
|
||||
* @param {string} name - Test name
|
||||
* @param {Function} fn - Async test function
|
||||
*/
|
||||
export function asyncTest(name, fn) {
|
||||
asyncQueue.push({ name, fn })
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all queued async tests sequentially
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function runAsyncTests() {
|
||||
for (const { name, fn } of asyncQueue) {
|
||||
try {
|
||||
await fn()
|
||||
results.passed++
|
||||
results.tests.push({ name, status: 'passed' })
|
||||
console.log(`✓ ${name}`)
|
||||
} catch (error) {
|
||||
results.failed++
|
||||
results.tests.push({ name, status: 'failed', error: error.message })
|
||||
console.error(`✗ ${name}`)
|
||||
console.error(` ${error.message}`)
|
||||
}
|
||||
}
|
||||
asyncQueue.length = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Get test results
|
||||
* @returns {Object}
|
||||
|
||||
Reference in New Issue
Block a user