question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating fake event objects for testing components.

See original GitHub issue

Say 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:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jelbourncommented, Jul 26, 2018

Yeah, though we may end up deciding that it’s something that’s more appropriate for the cdk.

1reaction
splincodecommented, Jul 26, 2018

@jelbourn Is the issue relevant?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found