3

I am new to Angular testing, and I want to perform 2 kinds of test for my application:

  1. Unit Test - I choose to use Jest since I can run my test without opening the browser, and it also supports testing for specific cases with --testNamePatern.
  2. End to end test - I want to try out Protractor since it is available in Angular and also has a big Angular community to work with.

My question is, can I use both Jest and Protractor in my application? If yes, do I need to configure anything to use both of them in my application.

3
  • Shouldn't be a problem. Just configure both of them the way you normally would. Shouldn't be an issue unless you are using mocha and jasmine in the same project. That will definitely give you headaches. Commented Nov 20, 2019 at 17:11
  • 1
    @tehbeardedone I was able to make it run with jest by changing the "types" in "tsconfig.json" file. However, I could not figure out how to change the config in "protractor.conf.js" for Jest to have the properties for the spec reporter. Could you help me to do it? Commented Nov 22, 2019 at 2:33
  • Sorry, I don't know anything about Jest or how to make it work with protractor. Commented Nov 22, 2019 at 14:54

1 Answer 1

7

You can use both jest and protractor in your application. By default the new angular cli release gives you a karma runner for unit tests and a protractor runner for end to end tests inside the same application. You are just changing Karma with Jest.

  1. Can I run protractor tests (end to end) with jest? No you cannot.

  2. Can I run unit tests using protractor? No you cannot.

  3. Can I run protractor for end to end tests and jest for unit tests in the same application? Yes you can. You will just need to tell jest which files to pick up and the same with protractor.

  4. Can I get both the reports in a single file or a single run? No you cannot. You will have to configure your jest runner to print reports which will be different from the protractor reports.

You can use both jest and protractor without configuring anything special. Here is a snippet of the package.json I am using for running e2e tests with protractor and lighthouse tests with jest.

{
  "name": "performance-tests",
  "version": "1.0.0",
  "description": "Performance tests and end to end tests.",
  "main": "jest.js",
  "scripts": {
    "debug": "node --inspect-brk ./node_modules/.bin/protractor protractor.conf.js",
    "pretest": "npm run tsc && npm run webdriver-update",
    "e2e": "npm run tsc && ./node_modules/protractor/bin/protractor protractor/compiled-js-files/protractor.conf.js",
    "grid": "sh run-grid.sh && npm run e2e",
    "tsc": "./node_modules/typescript/bin/tsc",
    "webdriver-update": "./node_modules/protractor/bin/webdriver-manager update --standalone --versions.standalone=3.8.0 --chrome --versions.chrome=78.0.3904.97",
    "lighthouse": "./node_modules/jest/bin/jest.js --verbose -t=lighthouse",
    "lighthouse-reports": "./node_modules/jest/bin/jest.js --verbose -t=lighthouse && node ./lighthouse/db.js"
  },
  "repository": {
    "type": "",
    "url": ""
  },
  "author": "Sankalan Parajuli",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "dependencies": {
    "@types/jasmine": "^3.3.12",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^12.12.14",
    "jasmine": "^3.3.1",
    "lighthouse": "^4.0.0-beta",
    "protractor": "5.4.2",
    "protractor-beautiful-reporter": "^1.3.3"
  },
  "devDependencies": {
    "@types/request": "^2.48.3",
    "@types/selenium-webdriver": "^4.0.0",
    "csvtojson": "^2.0.8",
    "jest": "^23.4.1",
    "moment": "^2.24.0",
    "mongodb": "^3.1.13",
    "puppeteer": "^1.6.0",
    "request-promise": "^4.2.5",
    "ts-node": "^8.5.2",
    "typescript": "2.8.1"
  }
}

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.