Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add component tracking test (svelte testing library)
  • Loading branch information
Lms24 committed Sep 2, 2022
commit dd187929f2d7f5335ded3e2fa056142d5ad59e87
56 changes: 56 additions & 0 deletions packages/svelte/test/performance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Scope } from '@sentry/hub';
import { render } from '@testing-library/svelte';

import DummyComponent from './components/Dummy.svelte';

let testTransaction = {
startChild: jest.fn(),
finish: jest.fn(),
};
let testUpdateSpan = { finish: jest.fn() };
let testInitSpan = { finish: jest.fn(), startChild: jest.fn(), transaction: testTransaction };

jest.mock('@sentry/hub', () => {
const original = jest.requireActual('@sentry/hub');
return {
...original,
getCurrentHub(): {
getScope(): Scope;
} {
return {
getScope(): any {
return {
getTransaction: () => {
return testTransaction;
},
};
},
};
},
};
});

describe('Sentry.trackComponent()', () => {
beforeEach(() => {
jest.resetAllMocks();

testTransaction.startChild.mockReturnValue(testInitSpan);
testInitSpan.startChild.mockReturnValue(testUpdateSpan);
});
it('creates nested init and update spans on component initialization', () => {
render(DummyComponent, { props: { options: {} } });

expect(testTransaction.startChild).toHaveBeenCalledWith({
description: '<Dummy>',
op: 'ui.svelte.init',
});

expect(testInitSpan.startChild as jest.Mock).toHaveBeenCalledWith({
description: '<Dummy>',
op: 'ui.svelte.update',
});

expect(testInitSpan.finish).toHaveBeenCalledTimes(1);
expect(testUpdateSpan.finish).toHaveBeenCalledTimes(1);
});
});