-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
Description
I recently moved to using harness testing to test opening and closing of dialogs in my app. I have multiple pages, each may have several scenarios where a confirmation/warning dialog is shown to the user and I have multiple tests for these scenarios on different spec files. Different tests fail depending on the order they run in (jasmine randomness), but the one thing that is consistent to all failed scenarios is the error appearing in the console:
TypeError: Cannot redefine property: defaultPrevented
Which stems from testbed/fake-events/event-objects#createKeyboardEvent.
After seeing this issue on webcomponents I made the following change in my local sources and all tests passed:
Object.defineProperty(event, 'defaultPrevented', { configurable: true, get: () => true });
I was unable to reproduce the scenario in stackblitz (all tests pass, no errors in console), but I'm not duplicating my full environment so I may be missing the trigger to this issue.
I suspect these issues are related to closing the dialog, as the Harness closes the dialog using the ESCAPE key. You can see in the stackblitz example I provided that I expect the number of open dialogs to be 0 after closing. In my failing tests, they sometimes fail that expectation.
Just to make sure I cover all bases, I noticed that when I added the dialog harness, I had to use harnesses for all other material components I was using on the page (table, button) or else tests would fail (sorry, I didn't document that issue, I "fixed it" and moved on). I don't know if this is related or not, but I thought that this dependency was a little curious.
Setup
Dependencies (partial):
"@angular/cdk": "~9.2.1",
"@angular/compiler": "~9.1.2",
"@angular/core": "~9.1.2",
"@angular/material": "^9.2.1",
Dev Dependencies (partial):
"@angular-devkit/build-angular": "~0.901.1",
"@angular/cli": "^9.1.1",
"@angular/compiler-cli": "~9.1.2",
"jasmine-core": "^3.5.0",
"jasmine-spec-reporter": "^5.0.1",
"karma": "^5.0.2",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-jasmine": "^3.1.1",
"karma-jasmine-html-reporter": "^1.5.3",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.8.3"
Environment:
Google Chrome Version 81.0.4044.138 (Official Build) (64-bit)
Mac OS Catalina Version 10.15.4