angular-extensions / pretty-html-log

A module that allows you to pretty print the inner HTML of ComponentFixtures, DebugElements, NativeElements or even plain HTML strings to the console. This is very useful for debugging Angular component tests in Jest
MIT License
38 stars 1 forks source link

logNgHTML is not a function #20

Closed diegorodridev closed 4 years ago

diegorodridev commented 4 years ago

I am having an strange error when trying to use this extension as part of my angular-jest testing environment.

I have done the following initial setup:

I have this environment in package.json

{
"@angular-extensions/pretty-html-log": "^3.1.1"
"@types/jest": "^26.0.9",
"@angular/cli": "^9.1.11",
"@angular/compiler-cli": "^9.1.12",
"@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0",
"babel-jest": "^26.3.0",
}

The estrange thing comes now, if I execute just console.logNgHTM(); Throws an error and says that it is missing parameters, this is the expected behaviour for an empty call. However, If I provide either console.logNgHTM(fixture) || console.logNgHTM(component), where component is the actual component being tested, it fails saying:

TypeError: console.logNgHTML is not a function

What am I missing? Any ideas?

daiyis commented 4 years ago

I am having the exact same error, Is there any secret setup?

nivekcode commented 4 years ago

Try adding your setupJest.ts to your tsconfig.spec.ts.

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "types": ["jest", "node"],
    "esModuleInterop": true
  },
  "files": ["polyfills.ts", "../jest.setup.ts"],
  "include": ["**/*.spec.ts", "**/*.d.ts"]
}
nivekcode commented 4 years ago

I will try to add this to the docs.

daiyis commented 4 years ago

Try adding your setupJest.ts to your tsconfig.spec.ts.

This seems doesn't solve the problem, and I suppose you are referring to the setupJest.ts file not jest.setup.ts in the sample code.

But It still failed with the same error message, though autocompletion is working fine.

diegorodridev commented 4 years ago

Thank you for the answer @kreuzerk but I still have the same problem. I have had that configuration since the beginning, but it doesn't work.

nivekcode commented 4 years ago

@daiyis and @diegorodridev thanks a lot for the feedback - is there a reproduction repo for this issue?