jest-decorated
jest-decorated copied to clipboard
Annotations are not defined after updating to 0.1.1

in my jest config
setupFilesAfterEnv: [
'./jest.setup.js'
, "@jest-decorated/core/globals"
],
in my setup.ts
import "@jest-decorated/core/globals";
module.exports = async function () {
};
other dependencies
"dependencies": {
"@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4",
"@jest-decorated/core": "^0.1.1",
"@types/jest": "^27.0.2",
"@types/node": "^14.0.23",
"axios": "^0.21.1",
"babel-jest": "^27.3.1",
"expect-playwright": "^0.2.5",
"jest": "^27.3.1",
"jest-allure": "^0.1.3",
"jest-circus": "^27.3.1",
"jest-circus-allure-environment": "^0.13.3",
"playwright": "^1.16.2"
},
Hello, @amrsalem1 !
Thanks for reporting the issue, you're absolutely right. In this case, we need to help the TS and explicitly reference our typings.
In your tsconfig.json
try adding your jest setup file:
{
"include": ["./setup.ts"]
}
or the jest-decorated lib itself:
{
"include": ["node_modules/@jest-decorated/core"]
}
(another example here)
If I won't be able to find a workaround/solution for this by the end of this week, I'll update the README
with this explanation
@vitalishapovalov thanks for the workaround but it didn't help unfortunately, annotation still undefined
@amrsalem1
okay, seems like the only way we can make it work properly with TS/editor is:
- in the
jest-config -> setupFilesAfterEnv
list we shouldn't include the jest-decorated lib itself; we need to create a separate.ts
file (setup.ts
), and include jest-decorated globals right inside that file (import "@jest-decorated/core/globals";
)
{
"setupFilesAfterEnv": ["<rootDir>/setup.ts"],
}
- in
tsconfig -> include
we need to include thesetup.ts
file:
{
"include": ["./setup.ts"],
}
If you've already tried this way, and it's still not working - may I take a look at folder structure, jest-config
and tsconfig
files?
@amrsalem1
any success here?
please, also make sure that the tests directory itself is also included in tsconfig -> include
list.
the final tsconfig -> include
setup should look something like:
{
"include": ["./setup.ts", "./__tests__"],
}
still facing same issue
here is my configs for jest
module.exports = {
runner: "groups",
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)"
],
testRunner: "jest-circus/runner",
globalSetup: '<rootDir>/setup.ts',
globalTeardown: '<rootDir>/teardown.ts',
setupFilesAfterEnv: [
'./jest.setup.js', "<rootDir>/setup.ts", "@jest-decorated/react/globals"
],
include: ["./setup.ts"],
testEnvironment: '<rootDir>/testEnvironment.js',
moduleFileExtensions: ["js", "json", "jsx", "ts", "tsx", "node"],
moduleDirectories: ["node_modules", "src", "./src/utils/checks"],
verbose: false,
reporters: [
"default",
// "<rootDir>/shiftReporter.ts"
]
};
setup.ts
import "@jest-decorated/core/globals";
module.exports = async function () {
};
error
my file structurer

You've added include: ["./setup.ts"],
to the jest.config.js
, but it should be added to the tsconfig.json
Please, try adding include: ["./setup.ts"],
to the tsconfig.json