Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Commit

Permalink
Change toEqual and toBe to toStrictEqual (#102)
Browse files Browse the repository at this point in the history
* Change toEqual to toStrictEqual

* Change toBe to toStrictEqual
  • Loading branch information
jingyi2811 authored May 21, 2021
1 parent 4d84b92 commit 6aa9f5b
Show file tree
Hide file tree
Showing 32 changed files with 386 additions and 387 deletions.
84 changes: 42 additions & 42 deletions packages/whale-api-client/__tests__/api/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('getBalance', () => {
it('should getBalance zero for bech32', async () => {
const address = await container.getNewAddress()
const balance = await client.address.getBalance(address)
expect(balance).toBe('0.00000000')
expect(balance).toStrictEqual('0.00000000')
})

it('should getBalance for bech32', async () => {
Expand All @@ -64,7 +64,7 @@ describe('getBalance', () => {
await service.waitForAddressTxCount(address, 1)

const balance = await client.address.getBalance(address)
expect(balance).toBe('1.23000000')
expect(balance).toStrictEqual('1.23000000')
})

it('should getBalance for legacy', async () => {
Expand All @@ -74,7 +74,7 @@ describe('getBalance', () => {
await service.waitForAddressTxCount(address, 1)

const balance = await client.address.getBalance(address)
expect(balance).toBe('1.92822343')
expect(balance).toStrictEqual('1.92822343')
})

it('should getBalance for p2sh', async () => {
Expand All @@ -84,7 +84,7 @@ describe('getBalance', () => {
await service.waitForAddressTxCount(address, 1)

const balance = await client.address.getBalance(address)
expect(balance).toBe('1.23419341')
expect(balance).toStrictEqual('1.23419341')
})
})

Expand All @@ -98,7 +98,7 @@ it('should getAggregation', async () => {
await service.waitForAddressTxCount(address, 3)

const agg = await client.address.getAggregation(address)
expect(agg).toEqual({
expect(agg).toStrictEqual({
amount: {
txIn: '24.38471696',
txOut: '0.00000000',
Expand All @@ -125,36 +125,36 @@ it('should getAggregation', async () => {
describe('tokens', () => {
it('should listToken', async () => {
const response = await client.address.listToken(address)
expect(response.length).toBe(5)
expect(response.hasNext).toBe(false)
expect(response.length).toStrictEqual(5)
expect(response.hasNext).toStrictEqual(false)

expect(response[0]).toEqual(expect.objectContaining({ id: '0', amount: '15.50000000', symbol: 'DFI' }))
expect(response[4]).toEqual(expect.objectContaining({ id: '4', amount: '10.00000000', symbol: 'D' }))
expect(response[0]).toStrictEqual(expect.objectContaining({ id: '0', amount: '15.50000000', symbol: 'DFI' }))
expect(response[4]).toStrictEqual(expect.objectContaining({ id: '4', amount: '10.00000000', symbol: 'D' }))
})

it('should paginate listToken', async () => {
const first = await client.address.listToken(address, 2)
expect(first.length).toBe(2)
expect(first.hasNext).toBe(true)
expect(first.nextToken).toBe('1')
expect(first.length).toStrictEqual(2)
expect(first.hasNext).toStrictEqual(true)
expect(first.nextToken).toStrictEqual('1')

expect(first[0]).toEqual(expect.objectContaining({ id: '0', amount: '15.50000000', symbol: 'DFI' }))
expect(first[1]).toEqual(expect.objectContaining({ id: '1', amount: '10.00000000', symbol: 'A' }))
expect(first[0]).toStrictEqual(expect.objectContaining({ id: '0', amount: '15.50000000', symbol: 'DFI' }))
expect(first[1]).toStrictEqual(expect.objectContaining({ id: '1', amount: '10.00000000', symbol: 'A' }))

const next = await client.paginate(first)
expect(next.length).toBe(2)
expect(next.hasNext).toBe(true)
expect(next.nextToken).toBe('3')
expect(next.length).toStrictEqual(2)
expect(next.hasNext).toStrictEqual(true)
expect(next.nextToken).toStrictEqual('3')

expect(next[0]).toEqual(expect.objectContaining({ id: '2', amount: '10.00000000', symbol: 'B' }))
expect(next[1]).toEqual(expect.objectContaining({ id: '3', amount: '10.00000000', symbol: 'C' }))
expect(next[0]).toStrictEqual(expect.objectContaining({ id: '2', amount: '10.00000000', symbol: 'B' }))
expect(next[1]).toStrictEqual(expect.objectContaining({ id: '3', amount: '10.00000000', symbol: 'C' }))

const last = await client.paginate(next)
expect(last.length).toBe(1)
expect(last.hasNext).toBe(false)
expect(last.length).toStrictEqual(1)
expect(last.hasNext).toStrictEqual(false)
expect(last.nextToken).toBeUndefined()

expect(last[0]).toEqual(expect.objectContaining({ id: '4', amount: '10.00000000', symbol: 'D' }))
expect(last[0]).toStrictEqual(expect.objectContaining({ id: '4', amount: '10.00000000', symbol: 'D' }))
})
})

Expand Down Expand Up @@ -188,10 +188,10 @@ describe('transactions', () => {
it('should listTransaction', async () => {
const transactions = await client.address.listTransaction(addressA.bech32)

expect(transactions.length).toBe(3)
expect(transactions.hasNext).toBe(false)
expect(transactions.length).toStrictEqual(3)
expect(transactions.hasNext).toStrictEqual(false)

expect(transactions[2]).toEqual({
expect(transactions[2]).toStrictEqual({
block: {
hash: expect.stringMatching(/[0-f]{64}/),
height: expect.any(Number)
Expand All @@ -216,27 +216,27 @@ describe('transactions', () => {

it('should paginate listTransaction', async () => {
const first = await client.address.listTransaction(addressA.bech32, 2)
expect(first.length).toBe(2)
expect(first.hasNext).toBe(true)
expect(first.length).toStrictEqual(2)
expect(first.hasNext).toStrictEqual(true)
expect(first.nextToken).toMatch(/[0-f]{80}/)

expect(first[0]).toEqual(expect.objectContaining({ value: '9.50000000', type: 'vin' }))
expect(first[1]).toEqual(expect.objectContaining({ value: '9.50000000', type: 'vout' }))
expect(first[0]).toStrictEqual(expect.objectContaining({ value: '9.50000000', type: 'vin' }))
expect(first[1]).toStrictEqual(expect.objectContaining({ value: '9.50000000', type: 'vout' }))

const next = await client.paginate(first)
expect(next.length).toBe(1)
expect(next.hasNext).toBe(false)
expect(next.length).toStrictEqual(1)
expect(next.hasNext).toStrictEqual(false)

expect(next[0]).toEqual(expect.objectContaining({ value: '34.00000000', type: 'vout' }))
expect(next[0]).toStrictEqual(expect.objectContaining({ value: '34.00000000', type: 'vout' }))
})

it('should listTransactionUnspent', async () => {
const unspent = await client.address.listTransactionUnspent(addressA.bech32)

expect(unspent.length).toBe(1)
expect(unspent.hasNext).toBe(false)
expect(unspent.length).toStrictEqual(1)
expect(unspent.hasNext).toStrictEqual(false)

expect(unspent[0]).toEqual({
expect(unspent[0]).toStrictEqual({
block: {
hash: expect.stringMatching(/[0-f]{64}/),
height: expect.any(Number)
Expand All @@ -259,19 +259,19 @@ describe('transactions', () => {

it('should paginate listTransactionUnspent', async () => {
const first = await client.address.listTransactionUnspent(addressB.bech32, 1)
expect(first.length).toBe(1)
expect(first.hasNext).toBe(true)
expect(first.length).toStrictEqual(1)
expect(first.hasNext).toStrictEqual(true)
expect(first.nextToken).toMatch(/[0-f]{80}/)

expect(first[0].vout.value).toBe('2.93719381')
expect(first[0].vout.value).toStrictEqual('2.93719381')

const next = await client.paginate(first)
expect(next.length).toBe(1)
expect(next.hasNext).toBe(true)
expect(next.length).toStrictEqual(1)
expect(next.hasNext).toStrictEqual(true)

expect(next[0].vout.value).toBe('9.49990000')
expect(next[0].vout.value).toStrictEqual('9.49990000')

const empty = await client.paginate(next)
expect(empty.length).toBe(0)
expect(empty.length).toStrictEqual(0)
})
})
41 changes: 20 additions & 21 deletions packages/whale-api-client/__tests__/api/poolpair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ describe('list', () => {
it('should list', async () => {
const response = await client.poolpair.list(30)

expect(response.length).toBe(8)
expect(response.hasNext).toBe(false)
expect(response.length).toStrictEqual(8)
expect(response.hasNext).toStrictEqual(false)

expect(response[1]).toEqual({
expect(response[1]).toStrictEqual({
id: '8',
symbol: 'A-C',
name: 'A-C',
Expand All @@ -94,7 +94,6 @@ describe('list', () => {
tradeEnabled: true,
ownerAddress: expect.any(String),
rewardPct: 0,
customRewards: undefined,
creation: {
tx: expect.any(String),
height: expect.any(Number)
Expand All @@ -104,38 +103,38 @@ describe('list', () => {

it('should list with pagination', async () => {
const first = await client.poolpair.list(3)
expect(first.length).toBe(3)
expect(first.hasNext).toBe(true)
expect(first.nextToken).toBe('9')
expect(first.length).toStrictEqual(3)
expect(first.hasNext).toStrictEqual(true)
expect(first.nextToken).toStrictEqual('9')

expect(first[0].symbol).toBe('A-B')
expect(first[1].symbol).toBe('A-C')
expect(first[2].symbol).toBe('A-D')
expect(first[0].symbol).toStrictEqual('A-B')
expect(first[1].symbol).toStrictEqual('A-C')
expect(first[2].symbol).toStrictEqual('A-D')

const next = await client.paginate(first)
expect(next.length).toBe(3)
expect(next.hasNext).toBe(true)
expect(next.nextToken).toBe('12')
expect(next.length).toStrictEqual(3)
expect(next.hasNext).toStrictEqual(true)
expect(next.nextToken).toStrictEqual('12')

expect(next[0].symbol).toBe('A-E')
expect(next[1].symbol).toBe('A-F')
expect(next[2].symbol).toBe('B-C')
expect(next[0].symbol).toStrictEqual('A-E')
expect(next[1].symbol).toStrictEqual('A-F')
expect(next[2].symbol).toStrictEqual('B-C')

const last = await client.paginate(next)
expect(last.length).toBe(2)
expect(last.hasNext).toBe(false)
expect(last.length).toStrictEqual(2)
expect(last.hasNext).toStrictEqual(false)
expect(last.nextToken).toBeUndefined()

expect(last[0].symbol).toBe('B-D')
expect(last[1].symbol).toBe('B-E')
expect(last[0].symbol).toStrictEqual('B-D')
expect(last[1].symbol).toStrictEqual('B-E')
})
})

describe('get', () => {
it('should get', async () => {
const response = await client.poolpair.get('7')

expect(response).toEqual({
expect(response).toStrictEqual({
id: '7',
symbol: 'A-B',
name: 'A-B',
Expand Down
12 changes: 6 additions & 6 deletions packages/whale-api-client/__tests__/api/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ describe('whitelisted rpc methods', () => {
it('should rpc.call(getblockchaininfo)', async () => {
const info = await client.rpc.call<blockchain.BlockchainInfo>('getblockchaininfo', [], 'number')

expect(info.chain).toBe('regtest')
expect(typeof info.blocks).toBe('number')
expect(info.chain).toStrictEqual('regtest')
expect(typeof info.blocks).toStrictEqual('number')
})

it('should rpc.call(getblockcount)', async () => {
const count = await client.rpc.call<number>('getblockcount', [], 'number')

expect(typeof count).toBe('number')
expect(typeof count).toStrictEqual('number')
})

it('should rpc.call(getblockhash)', async () => {
await container.generate(1)

const hash = await client.rpc.call<string>('getblockhash', [1], 'number')
expect(hash.length).toBe(64)
expect(hash.length).toStrictEqual(64)
})

it('should rpc.call(getblock)', async () => {
Expand All @@ -65,7 +65,7 @@ describe('whitelisted rpc methods', () => {
const hash = await client.rpc.call<string>('getblockhash', [1], 'number')
const block = await client.rpc.call<blockchain.Block<blockchain.Transaction>>('getblock', [hash], 'number')

expect(block.hash.length).toBe(64)
expect(Array.isArray(block.tx)).toBe(true)
expect(block.hash.length).toStrictEqual(64)
expect(Array.isArray(block.tx)).toStrictEqual(true)
})
})
18 changes: 9 additions & 9 deletions packages/whale-api-client/__tests__/api/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ afterAll(async () => {
describe('client.tokens.list()', () => {
it('should listTokens', async () => {
const result = await client.tokens.list()
expect(result.length).toBe(4)
expect(result.length).toStrictEqual(4)

expect(result[0]).toStrictEqual({
id: '0',
Expand Down Expand Up @@ -64,26 +64,26 @@ describe('client.tokens.list()', () => {
it('should listTokens with pagination', async () => {
const first = await client.tokens.list(2)

expect(first.length).toBe(2)
expect(first.hasNext).toBe(true)
expect(first.nextToken).toBe('1')
expect(first.length).toStrictEqual(2)
expect(first.hasNext).toStrictEqual(true)
expect(first.nextToken).toStrictEqual('1')

expect(first[0]).toStrictEqual(expect.objectContaining({ id: '0', symbol: 'DFI', symbolKey: 'DFI' }))
expect(first[1]).toStrictEqual(expect.objectContaining({ id: '1', symbol: 'DBTC', symbolKey: 'DBTC' }))

const next = await client.paginate(first)

expect(next.length).toBe(2)
expect(next.hasNext).toBe(true)
expect(next.nextToken).toBe('3')
expect(next.length).toStrictEqual(2)
expect(next.hasNext).toStrictEqual(true)
expect(next.nextToken).toStrictEqual('3')

expect(next[0]).toStrictEqual(expect.objectContaining({ id: '2', symbol: 'DETH', symbolKey: 'DETH' }))
expect(next[1]).toStrictEqual(expect.objectContaining({ id: '3', symbol: 'DBTC-DET', symbolKey: 'DBTC-DET' }))

const last = await client.paginate(next)

expect(last.length).toBe(0)
expect(last.hasNext).toBe(false)
expect(last.length).toStrictEqual(0)
expect(last.hasNext).toStrictEqual(false)
expect(last.nextToken).toBeUndefined()
})
})
Expand Down
Loading

0 comments on commit 6aa9f5b

Please sign in to comment.