Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocharc.yml require not working with chai/require-expect #51

Open
rightisleft opened this issue Mar 21, 2020 · 1 comment
Open

mocharc.yml require not working with chai/require-expect #51

rightisleft opened this issue Mar 21, 2020 · 1 comment

Comments

@rightisleft
Copy link

rightisleft commented Mar 21, 2020

Given that i have added chai/require-expect to the require array in mocharc.yml
When i run npx mocha
Then it should include expect as a global function

-- Actually --

I get the following error:

TSError: ⨯ Unable to compile TypeScript: test/isthisforfun.spec.ts:7:9 - error TS2304: Cannot find name 'expect'.

mocharc.yml

allow-uncaught: false
async-only: false
bail: false
check-leaks: false
color: true
delay: false
diff: true
exit: false # could be expressed as "no-exit: true"
extension:
  - ts
forbid-only: false
forbid-pending: false
full-trace: false
# fgrep and grep are mutually exclusive
# grep: something
growl: false
ignore:
  - node_modules
  - src
inline-diffs: false
# needs to be used with grep or fgrep
# invert: false
recursive: false
reporter: spec
require:
  - "ts-node/register"
  - "chai/register-expect"
retries: 1
slow: 75
sort: false
spec: test/**/*.spec.ts # the positional arguments!
timeout: false # same as "no-timeout: true" or "timeout: 0"
trace-warnings: true # node flags ok
ui: bdd
v8-stack-trace-limit: 100 # V8 flags are prepended with "v8-"
watch: false
watch-files:
  - 'test/**/*.ts'

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "lib": ["es2019"],
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noResolve": false,
    "noEmitOnError": false,
    "noImplicitAny": true,
    "declaration": true,
    "sourceMap": true,
    "outDir": "dist/",
    "moduleResolution": "node",
    "preserveSymlinks": true,
    "skipLibCheck": true,
    "types": [ "node", "mocha" ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts",
    "test/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

package.json

{
  "name": "isthisforfun",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/chai": "^4.2.11",
    "@types/mocha": "^7.0.2",
    "@types/node": "^13.9.2",
    "babel": "^6.23.0",
    "chai": "^4.2.0",
    "mocha": "^7.1.1",
    "ts-mocha": "^7.0.0",
    "ts-node": "^8.7.0",
    "typescript": "^3.8.3"
  },
  "dependencies": {
    "@types/axios": "^0.14.0",
    "axios": "^0.19.2"
  }
}

Hack Fix
If i include the library as an import in each test it passes

import { expect } from 'chai';  // Using Expect style
@rightisleft
Copy link
Author

Here's the example repository:
https://github.com/rightisleft/typescript-mocha-test-scaffold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant