0

I know that it's recommended to use karma/jasmine for component/unit testing but I want to do the same using protractor because of two reasons:

  • it's not possible to emulate 'Tab' behaviour in javascript to move to the next focusable element (Is there a way to programmatically trigger the TAB key to move the focus to the next focusable element?). I need to be able to test 'Tab', 'Esc', key combinations and with protractor it's as simple as calling sendKey.
  • karma/jasmine don't render css. You need to use setStyleFixtures which is a pain. The absence of css causes issues: for instance, jasmine/karma renders elements with 'display: none' and messes up the market (I'm not sure about this part but this is what happens when I create dx-data-grid).

I know that protractor is meant to be used to do e2e testing but because of those two key benefits, I wonder if there is an easy way to use a protractor to do unit testing/integration testing.

An ideal solution for me would be to write a regular jasmine test with TestBed(to mock dependencies using angular's DI) and test it using protractor API without creating angular routes and special pages.

Heads-up, I've used jasmine for a couple of months, I'm not very familiar with protractor.

aderesh
  • 927
  • 10
  • 22
  • I do not agree that Karma and Jasmine will not be able to serve the purpose of unit testing as per your requirement. Can you share the code which you were testing and what unit test you wrote ? For ref: https://shashankvivek-7.medium.com/say-hi-to-jasmine-karma-in-angular-intro-d728d669a1c7 – Shashank Vivek Nov 17 '20 at 07:17
  • Thanks for you reply. I have mentioned that it is not possible to test Tab to change focus using karma and attached another discussion. This is one of the main things I need. With which exactly you're not agree? – aderesh Nov 17 '20 at 10:08
  • Can you share the code which you have written for the same – Shashank Vivek Nov 17 '20 at 12:42
  • 1
    There is a way to attach selenium-webdriver to an Angular unit test but from what I remember; however, you remove the ability to debug the test. I would strongly strongly discourage trying to get Protractor to work with unit testing just because of the debugability and that Protractor is not made to do unit testing. You should use the Angular TestBed libraries (I think it is still called TestBed) – cnishina Nov 20 '20 at 06:11

0 Answers0