title: Test invalid function arguments with TypeScript and JestJS
body: <p>I've beend creating a node application with typescript and I'm using jest to write unit tests.</p>
  
  <p>My issue: I can't really write unit tests simulating invalid function argument types, because typescript won't compile. I mean it's nice that typescript realises that I try to put wrong data in those functions, but the way I understood ts so far is, it only works during compile time. There won't be any checks of argument types during runtime.</p>
  
  <p>So I still have to test the correct behaviour of my IO depending functions with jest, right?</p>
  
  <p>I thought I'll just write a xyz.spec.<strong>js</strong> that and leave all the interfaces and types behind for that specific test. But then I receive an error from jest regarding the import of modules. I guess because it's not a ts file.</p>
  
  <p>Do I have to change my jest or ts setup to make it work?</p>
  
  <p>Here is a screenshot of the test and the error:</p>
  
  <p><a href="https://i.stack.imgur.com/6Jmc9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6Jmc9.png" alt="enter image description here"></a></p>
  
  <p>here my package.json:</p>
  
  <pre><code>{
    "name": "state",
    "version": "0.0.0",
    "files": [
      "build"
    ],
    "main": "build/index",
    "types": "build/index",
    "scripts": {
      "clean": "rimraf build &amp;&amp; rimraf coverage",
      "format": "prettier --write \"{src,__tests__}/**/*.ts\" --single-quote --trailing-comma es5",
      "lint": "tslint --force --format verbose \"src/**/*.ts\"",
      "prepublishOnly": "npm run build",
      "start": "node ./build/index.js",
      "prebuild": "npm run clean &amp;&amp; npm run format &amp;&amp; npm run lint &amp;&amp; echo Using TypeScript &amp;&amp; tsc --version",
      "build": "tsc --pretty",
      "build:watch": "nodemon --legacy-watch src/index.ts",
      "test": "jest --no-cache",
      "test:watch": "jest --no-cache --watch",
      "coverage": "jest --no-cache --coverage"
    },
    "dependencies": {
      "mongoose": "^5.6.0"
    },
    "devDependencies": {
      "@types/jest": "^24.0.13",
      "@types/mongoose": "^5.5.6",
      "@types/node": "^10.14.7",
      "coveralls": "^3.0.2",
      "jest": "^24.8.0",
      "nodemon": "^1.19.0",
      "prettier": "^1.14.3",
      "rimraf": "^2.6.2",
      "ts-jest": "^24.0.2",
      "ts-node": "^8.1.0",
      "tslint": "^5.11.0",
      "tslint-config-prettier": "^1.15.0",
      "typescript": "^3.1.1"
    },
    "engines": {
      "node": "&gt;=10.0.0"
    },
    "jest": {
      "preset": "ts-jest"
    }
  }
  </code></pre>
  
  <p>and here my tsconfig.json:</p>
  
  <pre><code>{
    "compilerOptions": {
      "declaration": true,
      "module": "commonjs",
      "moduleResolution": "node",
      "lib": ["esnext"],
      "target": "es2015",
      "outDir": "./&lt;%= buildpath %&gt;",
      "removeComments": true,
      "inlineSourceMap": true,
      "inlineSources": true,
      "preserveConstEnums": true,
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "strict": true,
      "noUnusedLocals": true,
      "noUnusedParameters": true,
      "noImplicitReturns": true,
      "noFallthroughCasesInSwitch": true
    },
    "include": ["src/**/*"],
    "exclude": ["node_modules", "build"]
  }
  </code></pre>
  
  <p>Best regards
  fea</p>