sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.8k stars 105 forks source link

wrong message: Expected `e` to be of type .... - instead of Expected argument to be of type #236

Open pmunin opened 2 years ago

pmunin commented 2 years ago

Simple code:

ow([123], 'myValues', ow.array.ofType(ow.string))

All of a sudden started giving me the following error message:

'(array `myValues`) Expected `e` to be of type `string` but received type `number`'

Previously it was giving me the right message

'(array `myValues`) Expected argument to be of type `string` but received type `number`'

This behavior happens during jest test run.

The changes I made in my package.json/devDependencies:

- "jest": "^26.6.3",
+ "jest": "^27.5.1",

-  "@types/jest": "^24.0.11",
+  "@types/jest": "^27.4.1",

-  "ts-jest": "^26.5.5",
+ "ts-jest": "^27.1.3",
sindresorhus commented 2 years ago

Are you minifying the code? e sounds like a minified identifier.

pmunin commented 2 years ago

It does look like minifier, but I didn't change anything else in my configs. And once I rolled back those dependencies (jest + ts-ject) to older versions - it started working fine again. So it's obviously the problem in ts-jest.

Here is my jest.config:

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  modulePathIgnorePatterns: ['<rootDir>/dist/'],
  moduleNameMapper: {
    '@/(.+)': '<rootDir>/src/$1'
  },
  clearMocks: true,
  resetMocks: true,
  testMatch: ['**/tests/**/*.[jt]s?(x)', '<rootDir>/src/**/*.test.ts'],
  testPathIgnorePatterns: ['<rootDir>/tests/helpers', '<rootDir>/tests/fixtures', '<rootDir>/tests/dbaccess', '<rootDir>/tests/setupTests.ts'],
  setupFilesAfterEnv: ['<rootDir>/tests/setupTests.ts'],
  testTimeout: 30000
}

here is my tsconfig.json:

{
  "extends": "@sindresorhus/tsconfig",
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2018",
    "esModuleInterop": true,
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": "./src",
    "paths": {
      "@/*": ["./*"]
    },
    "noUncheckedIndexedAccess": false,
    "noPropertyAccessFromIndexSignature": false
  },
  "exclude": ["node_modules", "dist"],
  "include": ["src"]
}
bgornicki commented 2 years ago

I experience similar problem in mocha unit tests (will check if it also affects production code) - seeing wrong argument name in error message.