Skip to content

Commit 3733aaf

Browse files
committed
lint
1 parent 87cd29e commit 3733aaf

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

src/util/testing-utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,25 +536,27 @@ export const mockWebSocketProvider = (provider: typeof WebSocketClassProvider):
536536
//
537537
// Throws (and logs, in case the error is caught by the code under test):
538538
// Error: Property 'obj.foo.baz' does not exist
539-
export function makeStub<T>(name: string, target: T): T {
540-
if (target === null || typeof target !== 'object') {
541-
return target
539+
export function makeStub<T>(name: string, obj: T): T {
540+
if (obj === null || typeof obj !== 'object') {
541+
return obj
542542
}
543-
return new Proxy(target, {
543+
return new Proxy(obj, {
544544
get: (target, prop) => {
545545
const propName = `${name}.${String(prop)}`
546546
if (!(prop in target) && !isStubPropAllowedUndefined(prop)) {
547547
const message = `Property '${propName}' does not exist`
548+
// eslint-disable-next-line no-console
548549
console.error(message)
549550
throw new Error(message)
550551
}
552+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
551553
return makeStub(propName, (target as any)[prop])
552554
},
553555
}) as T
554556
}
555557

556558
// Properties checked by jest which don't need to be defined:
557-
export let allowedUndefinedStubProps = [
559+
export const allowedUndefinedStubProps = [
558560
'$$typeof',
559561
'nodeType',
560562
'tagName',
@@ -566,7 +568,7 @@ export let allowedUndefinedStubProps = [
566568
'then',
567569
]
568570

569-
const isStubPropAllowedUndefined = (prop: string | Symbol) => {
571+
const isStubPropAllowedUndefined = (prop: string | symbol) => {
570572
if (typeof prop === 'symbol') {
571573
return true
572574
}

test/util/testing-utils.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ test('accessing an absent field should throw an error', async (t) => {
3333

3434
t.throws(
3535
() => {
36-
// @ts-ignore
37-
stub.count
36+
// @ts-expect-error intended
37+
t.is(stub.count, undefined)
3838
},
3939
{
4040
message: "Property 'stub.count' does not exist",
@@ -52,8 +52,8 @@ test('accessing a nested absent field should throw an error', async (t) => {
5252

5353
t.throws(
5454
() => {
55-
// @ts-ignore
56-
stub.nested.name
55+
// @ts-expect-error intended
56+
t.is(stub.nested.name, undefined)
5757
},
5858
{
5959
message: "Property 'stub.nested.name' does not exist",
@@ -67,9 +67,9 @@ test('fields used by jest are allowed to be undefined', async (t) => {
6767
count: 5,
6868
})
6969

70-
// @ts-ignore
70+
// @ts-expect-error intended
7171
t.is(stub.nodeType, undefined)
72-
// @ts-ignore
72+
// @ts-expect-error intended
7373
t.is(stub.tagName, undefined)
7474
})
7575

@@ -79,7 +79,7 @@ test('Symbol props are allowed to be undefined', async (t) => {
7979
count: 5,
8080
})
8181

82-
// @ts-ignore
82+
// @ts-expect-error intended
8383
t.is(stub[Symbol('my symbol')], undefined)
8484
})
8585

@@ -93,8 +93,8 @@ test('allowedUndefinedStubProps can be extended and restored', async (t) => {
9393

9494
t.throws(
9595
() => {
96-
// @ts-ignore
97-
stub[customProp]
96+
// @ts-expect-error intended
97+
t.is(stub[customProp], undefined)
9898
},
9999
{
100100
message: "Property 'stub.myCustomProp' does not exist",
@@ -103,15 +103,15 @@ test('allowedUndefinedStubProps can be extended and restored', async (t) => {
103103

104104
allowedUndefinedStubProps.push('myCustomProp')
105105

106-
// @ts-ignore
106+
// @ts-expect-error intended
107107
t.is(stub[customProp], undefined)
108108

109109
allowedUndefinedStubProps.pop()
110110

111111
t.throws(
112112
() => {
113-
// @ts-ignore
114-
stub[customProp]
113+
// @ts-expect-error intended
114+
t.is(stub[customProp], undefined)
115115
},
116116
{
117117
message: "Property 'stub.myCustomProp' does not exist",

0 commit comments

Comments
 (0)