Creating fake event objects for testing components.
See original GitHub issueSay I want to test a component behavior where preventDefault()
or stopPropagation()
is called on some event.
In vanilla JS land, I would create a fake event object, passing it to the event handler and be done with it. However, with types, any fake event has to line up with the expected event type for both TS and Dart. One could almost just do class FakeEvent extends Event
, but IE doesn’t support instantiating event objects with new
.
From here, there’s no clear way of getting a fake event object that works with the handler’s signature
Issue Analytics
- State:
- Created 8 years ago
- Reactions:7
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Creating fake test events with Typescript + Jest - Evan Teague
To create the fake event object on line 23, it's probably best to work backwards. You'll need to look up the types here....
Read more >Simulating Events in Angular Unit Tests | by Netanel Basal
In this article, I will walk you through the process of triggering events when writing unit tests for Angular components.
Read more >Simulate Browser Events in React with React Testing Library
When unit testing React components, it's often useful to be able to simulate browser events. This enables us to assert that event handlers ......
Read more >Passing a mock DOM event to component method in Angular ...
I cannot find a way to pass the event object to the method in the unit test case for example: test('it should call...
Read more >Using stubs to isolate parts of your app for testing
[TestClass] class TestStockAnalyzer { [TestMethod] public void TestContosoStockPrice() { // Arrange: // Create the fake stockFeed: IStockFeed ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, though we may end up deciding that it’s something that’s more appropriate for the cdk.
@jelbourn Is the issue relevant?