angular e2e tests - json object forEach method used in data driven tests throw "not a function error"

18 Views Asked by At

Have a data.json file and trying to use json data in e2e tests as given in below example. https://www.c-sharpcorner.com/article/data-driven-testing-in-protractor/

The example works fine with github version. Same implementation throw below error with Angular 12 and latest version. It seems the typescript version is unable to recognize the data object as array type. Not sure where to look at. Any help on this is apprecicated.

  • TypeError: calcJson.forEach is not a function

Below is the tsconfig setting:

"compilerOptions": { "baseUrl": "./", "downlevelIteration": true, "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "module": "es2020", "moduleResolution": "node", "experimentalDecorators": true, "importHelpers": true, "target": "es2015", "resolveJsonModule": true, "esModuleInterop": true, "typeRoots": [ "node_modules/@types" ], "lib": [ "es2018", "dom" ],

Package.json file:

"@angular-devkit/build-angular": "~12.2.7", "@angular/cli": "~12.2.7", "@angular/compiler-cli": "~12.2.7", "@angular/language-service": "~12.2.7", "@types/jasmine": "~3.6.0", "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", "codelyzer": "^6.0.0", "concat": "^1.0.3", "fs-extra": "^8.1.0", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~5.0.0", "karma": "~5.0.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage-istanbul-reporter": "~3.0.2", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "^1.5.0", "mini-css-extract-plugin": "^2.3.0", "protractor": "~7.0.0", "protractor-beautiful-reporter": "^1.3.6", "ts-node": "~7.0.0", "tslint": "~6.1.0", "typescript": "~4.3.5"

0

There are 0 best solutions below