Skip to content

Commit

Permalink
fix(tests): migrate chai v5, lint (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hieuzest authored Aug 15, 2024
1 parent ac9b6f5 commit c239d6c
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions packages/tests/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chai, { use } from 'chai'
import { config, use, util } from 'chai'
import promised from 'chai-as-promised'
import shape from './shape'
import { isNullable } from 'cosmokit'
Expand All @@ -8,44 +8,44 @@ use(promised)

function type(obj) {
if (typeof obj === 'undefined') {
return 'undefined';
return 'undefined'
}

if (obj === null) {
return 'null';
return 'null'
}

const stringTag = obj[Symbol.toStringTag];
const stringTag = obj[Symbol.toStringTag]
if (typeof stringTag === 'string') {
return stringTag;
return stringTag
}
const sliceStart = 8;
const sliceEnd = -1;
return Object.prototype.toString.call(obj).slice(sliceStart, sliceEnd);
const sliceStart = 8
const sliceEnd = -1
return Object.prototype.toString.call(obj).slice(sliceStart, sliceEnd)
}

function getEnumerableKeys(target) {
var keys: string[] = [];
for (var key in target) {
keys.push(key);
const keys: string[] = []
for (const key in target) {
keys.push(key)
}
return keys;
return keys
}

function getEnumerableSymbols(target) {
var keys: symbol[] = [];
var allKeys = Object.getOwnPropertySymbols(target);
for (var i = 0; i < allKeys.length; i += 1) {
var key = allKeys[i];
const keys: symbol[] = []
const allKeys = Object.getOwnPropertySymbols(target)
for (let i = 0; i < allKeys.length; i += 1) {
const key = allKeys[i]
if (Object.getOwnPropertyDescriptor(target, key)?.enumerable) {
keys.push(key);
keys.push(key)
}
}
return keys;
return keys
}

chai.config.deepEqual = (expected, actual, options) => {
return chai.util.eql(expected, actual, {
config.deepEqual = (expected, actual, options) => {
return util.eql(expected, actual, {
comparator: (expected, actual) => {
if (isNullable(expected) && isNullable(actual)) return true
if (type(expected) === 'Object' && type(actual) === 'Object') {
Expand All @@ -55,9 +55,9 @@ chai.config.deepEqual = (expected, actual, options) => {
...getEnumerableSymbols(expected),
...getEnumerableSymbols(actual),
])
return [...keys].every(key => chai.config.deepEqual!(expected[key], actual[key], options))
return [...keys].every(key => config.deepEqual!(expected[key], actual[key], options))
}
return null
}
},
})
}

0 comments on commit c239d6c

Please sign in to comment.