mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-05 16:58:01 +00:00
feat: Jest Test Runner (#2170)
This commit is contained in:
@@ -1,23 +1,35 @@
|
||||
import { assert } from 'chai'
|
||||
import { RippledError } from 'xrpl-local'
|
||||
|
||||
import { setupClient, teardownClient } from './setupClient'
|
||||
import { RippledError } from '../src'
|
||||
|
||||
import {
|
||||
setupClient,
|
||||
teardownClient,
|
||||
type XrplTestContext,
|
||||
} from './setupClient'
|
||||
import { assertRejects } from './testUtils'
|
||||
|
||||
describe('mock rippled tests', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
let testContext: XrplTestContext
|
||||
|
||||
beforeEach(async () => {
|
||||
testContext = await setupClient()
|
||||
})
|
||||
afterEach(async () => teardownClient(testContext))
|
||||
it('errors if a mock is not provided', async function () {
|
||||
this.mockRippled.suppressOutput = true
|
||||
if (testContext.mockRippled) {
|
||||
testContext.mockRippled.suppressOutput = true
|
||||
}
|
||||
|
||||
await assertRejects(
|
||||
this.client.request({ command: 'server_info' }),
|
||||
testContext.client.request({ command: 'server_info' }),
|
||||
RippledError,
|
||||
)
|
||||
})
|
||||
|
||||
it('provide bad response shape', async function () {
|
||||
try {
|
||||
this.mockRippled.addResponse('account_info', { data: {} })
|
||||
testContext.mockRippled!.addResponse('account_info', { data: {} })
|
||||
assert.fail('Should have errored')
|
||||
} catch (err) {
|
||||
if (!(err instanceof Error)) {
|
||||
@@ -27,12 +39,12 @@ describe('mock rippled tests', function () {
|
||||
})
|
||||
|
||||
it('provide bad response shape in function', async function () {
|
||||
this.mockRippled.suppressOutput = true
|
||||
this.mockRippled.addResponse('account_info', (request) => {
|
||||
testContext.mockRippled!.suppressOutput = true
|
||||
testContext.mockRippled!.addResponse('account_info', (request) => {
|
||||
return { data: request }
|
||||
})
|
||||
await assertRejects(
|
||||
this.client.request({ command: 'account_info', account: '' }),
|
||||
testContext.client.request({ command: 'account_info', account: '' }),
|
||||
RippledError,
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user