Skip to content

test(svelte): Add Svelte Testing Library and trackComponent tests #5686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 5, 2022

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Sep 2, 2022

This PR adds the Svelte Testing Library to the Svelte SDK. More specifically, two dev dependencies:

  • @testing-library/svelte which lets us test Svelte components
  • svelte-jester which is responsible to transform Svelte components to JS in Jest tests

The nice thing about this is that Svelte Testing Library offers us a way to simulate the rendering and mounting process of Svelte components. This means that we can properly test the trackComponent function without having to manually go in and simulate life cycle hooks calls. While in #5612, we added tests for the component tracking preprocessor, we didn't add tests for the actual tracking implementation.

Therefore, this PR also adds a bunch of test for trackComponent. I think this especially valuable because it is also public API and users can manually call this function if they don't want to use our preprocessor.

ref: #5671

jest.resetAllMocks();
testTransaction.spans = [];

testTransaction.startChild.mockImplementation(spanCtx => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes, Jest is a mystery to me. Apparently, mockImplementation (or mockReturnValue) must be called inside a describe or it/test function, while I can create empty jest.fn() mocks anywhere. I find this a little weird but whatever

@Lms24 Lms24 requested a review from lforst September 2, 2022 08:38
@Lms24 Lms24 self-assigned this Sep 2, 2022
@Lms24 Lms24 added Type: Tests Package: svelte Issues related to the Sentry Svelte SDK labels Sep 2, 2022
@Lms24 Lms24 added this to the Svelte SDK milestone Sep 2, 2022
@Lms24 Lms24 mentioned this pull request Sep 2, 2022
7 tasks
@Lms24 Lms24 force-pushed the lms-svelte-testing-library branch from beaf0f1 to 3efa16d Compare September 2, 2022 09:49
@Lms24 Lms24 force-pushed the lms-svelte-testing-library branch from d3bf11f to 30311ef Compare September 2, 2022 10:03
@Lms24 Lms24 requested a review from AbhiPrasad September 2, 2022 10:31
@lforst lforst merged commit 549370c into master Sep 5, 2022
@lforst lforst deleted the lms-svelte-testing-library branch September 5, 2022 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: svelte Issues related to the Sentry Svelte SDK Type: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants