Skip to content

Commit d92281f

Browse files
authored
refactor: compare with undefined directly instead of using typeof (#1935)
1 parent 0cae57a commit d92281f

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/matchers/element/toHaveAttribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export async function toHaveAttribute(
8282
options,
8383
})
8484

85-
const result = typeof value !== 'undefined'
85+
const result = value !== undefined
8686
// Name and value is passed in e.g. el.toHaveAttribute('attr', 'value', (opts))
8787
? await toHaveAttributeAndValue.call(this, received, attribute, value, options)
8888
// Only name is passed in e.g. el.toHaveAttribute('attr')

src/matchers/mock/toBeRequestedWith.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function toBeRequestedWith(
8888
* is actual method matching an expected method or methods
8989
*/
9090
const methodMatcher = (method: string, expected?: string | Array<string>) => {
91-
if (typeof expected === 'undefined') {
91+
if (expected === undefined) {
9292
return true
9393
}
9494
if (!Array.isArray(expected)) {
@@ -108,7 +108,7 @@ const methodMatcher = (method: string, expected?: string | Array<string>) => {
108108
* is actual statusCode matching an expected statusCode or statusCodes
109109
*/
110110
const statusCodeMatcher = (statusCode: number, expected?: number | Array<number>) => {
111-
if (typeof expected === 'undefined') {
111+
if (expected === undefined) {
112112
return true
113113
}
114114
if (!Array.isArray(expected)) {
@@ -124,7 +124,7 @@ const urlMatcher = (
124124
url: string,
125125
expected?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
126126
) => {
127-
if (typeof expected === 'undefined') {
127+
if (expected === undefined) {
128128
return true
129129
}
130130
if (typeof expected === 'function') {
@@ -148,7 +148,7 @@ const headersMatcher = (
148148
* if header matcher is an empty object, match with no headers
149149
*/
150150
if (
151-
typeof expected === 'undefined' ||
151+
expected === undefined ||
152152
typeof expected === 'object' && Object.keys(expected).length === 0
153153
) {
154154
return true
@@ -267,7 +267,7 @@ const minifyRequestMock = (
267267
},
268268
requestedWith?: ExpectWebdriverIO.RequestedWith
269269
) => {
270-
if (typeof requestMock === 'undefined') {
270+
if (requestMock === undefined) {
271271
return requestMock
272272
}
273273

@@ -320,7 +320,7 @@ const requestedWithParamToString = (
320320
| undefined,
321321
transformFn?: (param: ExpectWebdriverIO.JsonCompatible) => ExpectWebdriverIO.JsonCompatible | string
322322
) => {
323-
if (typeof param === 'undefined') {
323+
if (param === undefined) {
324324
return
325325
}
326326

@@ -394,7 +394,7 @@ const shortenString = (str: string, limit = STR_LIMIT) => {
394394

395395
const deleteUndefinedValues = (obj: Record<string, unknown>, baseline = obj) => {
396396
Object.keys(obj).forEach((k) => {
397-
if (typeof baseline[k] === 'undefined') {
397+
if (baseline[k] === undefined) {
398398
delete obj[k]
399399
}
400400
})

0 commit comments

Comments
 (0)