-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Connect performance marks to DOM elements (#2345)
- Loading branch information
1 parent
09430c0
commit ffcd645
Showing
7 changed files
with
121 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/internal/hooks/use-performance-marks/__tests__/use-performance-marks.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useRef } from 'react'; | ||
import { renderToStaticMarkup } from 'react-dom/server'; | ||
import { render } from '@testing-library/react'; | ||
import { usePerformanceMarks } from '../index'; | ||
|
||
function Demo() { | ||
const ref = useRef<HTMLDivElement>(null); | ||
const attributes = usePerformanceMarks('test-component', true, ref, () => ({}), []); | ||
return <div {...attributes} ref={ref} data-testid="element" />; | ||
} | ||
|
||
describe('Data attribute', () => { | ||
test('the attribute should be present after the first render', () => { | ||
const { getByTestId } = render(<Demo />); | ||
|
||
expect(getByTestId('element')).toHaveAttribute('data-analytics-performance-mark'); | ||
}); | ||
|
||
test('the attribute should be present after re-rendering', () => { | ||
const { getByTestId, rerender } = render(<Demo />); | ||
|
||
const attributeValueBefore = getByTestId('element').getAttribute('data-analytics-performance-mark'); | ||
|
||
rerender(<Demo />); | ||
|
||
expect(getByTestId('element')).toHaveAttribute('data-analytics-performance-mark'); | ||
|
||
const attributeValueAfter = getByTestId('element').getAttribute('data-analytics-performance-mark'); | ||
|
||
expect(attributeValueAfter).toBe(attributeValueBefore); | ||
}); | ||
|
||
test('should not render the attribute during server-side rendering', () => { | ||
const markup = renderToStaticMarkup(<Demo />); | ||
|
||
expect(markup).toBe('<div data-testid="element"></div>'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters