Skip to content

Commit

Permalink
refactor: revert breaking change to pluralize function
Browse files Browse the repository at this point in the history
  • Loading branch information
geersch committed Apr 8, 2024
1 parent 725605f commit 1b0edee
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/expect/src/jest-asymmetric-matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class CloseTo extends AsymmetricMatcher<number> {
return [
this.toString(),
this.sample,
`(${this.precision} ${pluralize('digit', this.precision)})`,
`(${pluralize('digit', this.precision)})`,
].join(' ')
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { MockInstance } from '@vitest/spy'
import { isMockFunction } from '@vitest/spy'
import type { Test } from '@vitest/runner'
import type { Assertion, ChaiPlugin } from './types'
import { arrayBufferEquality, generateToBeMessage, getObjectSubset, iterableEquality, equals as jestEquals, pluralize, sparseArrayEquality, subsetEquality, typeEquality } from './jest-utils'
import { arrayBufferEquality, generateToBeMessage, getObjectSubset, iterableEquality, equals as jestEquals, sparseArrayEquality, subsetEquality, typeEquality } from './jest-utils'
import type { AsymmetricMatcher } from './jest-asymmetric-matchers'
import { diff, getCustomEqualityTesters, stringify } from './jest-matcher-utils'
import { JEST_MATCHERS_OBJECT } from './constants'
Expand Down Expand Up @@ -175,7 +175,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
],
)
if ((pass && isNot) || (!pass && !isNot)) {
const message = stripped === 0 ? msg : `${msg}\n(${stripped} matching ${pluralize('property', stripped)} omitted from actual)`
const message = stripped === 0 ? msg : `${msg}\n(${stripped} matching ${stripped === 1 ? 'property' : 'properties'} omitted from actual)`
throw new AssertionError(message, { showDiff: true, expected, actual: actualSubset })
}
})
Expand Down
6 changes: 1 addition & 5 deletions packages/expect/src/jest-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,8 @@ export function generateToBeMessage(deepEqualityName: string, expected = '#{this
return toBeMessage
}

const IRREGULAR_PLURALS: { [key: string]: string } = {
property: 'properties',
}

export function pluralize(word: string, count: number): string {
return count === 1 ? word : IRREGULAR_PLURALS[word] ?? `${word}s`
return `${count} ${word}${count === 1 ? '' : 's'}`
}

export function getObjectKeys(object: object): Array<string | symbol> {
Expand Down

0 comments on commit 1b0edee

Please sign in to comment.