0

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"

Patri
  • 3
  • 4
  • Have you tried to debug the problem, for example, by printing the value of `calcJson`? – Phu Ngo Mar 11 '22 at 03:30
  • thank you for quick response. here is the print value of calcJson.. : {"0":{"num1":10,"num2":10,"result":20},"1":{"num1":100,"num2":100,"result":200},"2":{"num1":1,"num2":1,"result":2},"default":[{"num1":10,"num2":10,"result":20},{"num1":100,"num2":100,"result":200},{"num1":1,"num2":1,"result":2}]} – Patri Mar 11 '22 at 04:04
  • and here is the json array object created in external file .[{ "num1":10, "num2":10, "result":20 },{ "num1":100, "num2":100, "result":200 },{ "num1":1, "num2":1, "result":2 } ] – Patri Mar 11 '22 at 04:05
  • yes it did , thank you !! the sample uploaded in github worked with import * as aliasobject syntax.. this answers my question!! – Patri Mar 11 '22 at 04:18

0 Answers0