refactor: includes instead of indexOf (#5117)

This commit is contained in:
btea 2022-01-21 01:36:48 -06:00 committed by GitHub
parent c64907d261
commit 63210fe41a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -1044,7 +1044,7 @@ function parseTextData(
if ( if (
mode === TextModes.RAWTEXT || mode === TextModes.RAWTEXT ||
mode === TextModes.CDATA || mode === TextModes.CDATA ||
rawText.indexOf('&') === -1 !rawText.includes('&')
) { ) {
return rawText return rawText
} else { } else {

View File

@ -157,7 +157,7 @@ export function legacyCheckKeyCodes(
function isKeyNotMatch<T>(expect: T | T[], actual: T): boolean { function isKeyNotMatch<T>(expect: T | T[], actual: T): boolean {
if (isArray(expect)) { if (isArray(expect)) {
return expect.indexOf(actual) === -1 return !expect.includes(actual)
} else { } else {
return expect !== actual return expect !== actual
} }

View File

@ -345,7 +345,7 @@ function matches(pattern: MatchPattern, name: string): boolean {
if (isArray(pattern)) { if (isArray(pattern)) {
return pattern.some((p: string | RegExp) => matches(p, name)) return pattern.some((p: string | RegExp) => matches(p, name))
} else if (isString(pattern)) { } else if (isString(pattern)) {
return pattern.split(',').indexOf(name) > -1 return pattern.split(',').includes(name)
} else if (pattern.test) { } else if (pattern.test) {
return pattern.test(name) return pattern.test(name)
} }

View File

@ -1,7 +1,7 @@
expect.extend({ expect.extend({
toHaveBeenWarned(received: string) { toHaveBeenWarned(received: string) {
asserted.add(received) asserted.add(received)
const passed = warn.mock.calls.some(args => args[0].indexOf(received) > -1) const passed = warn.mock.calls.some(args => args[0].includes(received))
if (passed) { if (passed) {
return { return {
pass: true, pass: true,
@ -23,7 +23,7 @@ expect.extend({
toHaveBeenWarnedLast(received: string) { toHaveBeenWarnedLast(received: string) {
asserted.add(received) asserted.add(received)
const passed = const passed =
warn.mock.calls[warn.mock.calls.length - 1][0].indexOf(received) > -1 warn.mock.calls[warn.mock.calls.length - 1][0].includes(received)
if (passed) { if (passed) {
return { return {
pass: true, pass: true,
@ -43,7 +43,7 @@ expect.extend({
asserted.add(received) asserted.add(received)
let found = 0 let found = 0
warn.mock.calls.forEach(args => { warn.mock.calls.forEach(args => {
if (args[0].indexOf(received) > -1) { if (args[0].includes(received)) {
found++ found++
} }
}) })
@ -78,7 +78,7 @@ afterEach(() => {
.map(args => args[0]) .map(args => args[0])
.filter(received => { .filter(received => {
return !assertedArray.some(assertedMsg => { return !assertedArray.some(assertedMsg => {
return received.indexOf(assertedMsg) > -1 return received.includes(assertedMsg)
}) })
}) })
warn.mockRestore() warn.mockRestore()