|
1 | 1 | import React from 'react';
|
2 |
| -import { render } from '@testing-library/react'; |
| 2 | +import { render, waitFor } from '@testing-library/react'; |
3 | 3 | import { ConfigApi, configApiRef } from '@backstage/core-plugin-api';
|
4 | 4 | import { TestApiProvider } from '@backstage/test-utils';
|
5 | 5 | import { PlausibleAnalytics } from './components/PlausibleAnalytics';
|
@@ -34,26 +34,31 @@ describe('PlausibleAnalytics', () => {
|
34 | 34 | expect(container.firstChild).toBeNull();
|
35 | 35 | });
|
36 | 36 |
|
37 |
| - it('renders script tag when plausible is enabled and domain is provided', () => { |
| 37 | + it('renders script tag when plausible is configured', async () => { |
38 | 38 | const config = mockConfigApi({
|
39 | 39 | plausible: {
|
40 | 40 | enabled: true,
|
41 | 41 | dataDomain: 'example.com',
|
42 |
| - sourceDomain: 'plausible.example.com', |
| 42 | + sourceUrl: 'https://plausible.example.com/js/script.js', |
43 | 43 | },
|
44 | 44 | });
|
45 |
| - const { container } = render( |
| 45 | + render( |
46 | 46 | <TestApiProvider apis={[[configApiRef, config]]}>
|
47 | 47 | <PlausibleAnalytics />
|
48 | 48 | </TestApiProvider>,
|
49 | 49 | );
|
50 |
| - const scriptTag = container.querySelector('script'); |
51 |
| - expect(scriptTag).toBeInTheDocument(); |
52 |
| - expect(scriptTag).toHaveAttribute('data-domain', 'example.com'); |
53 |
| - expect(scriptTag).toHaveAttribute( |
54 |
| - 'src', |
55 |
| - 'https://plausible.example.com/js/script.js', |
56 |
| - ); |
57 |
| - expect(scriptTag).toHaveAttribute('defer'); |
| 50 | + |
| 51 | + await waitFor(() => { |
| 52 | + const scriptTag = document.querySelector( |
| 53 | + 'script[data-domain="example.com"]', |
| 54 | + ); |
| 55 | + expect(scriptTag).toBeInTheDocument(); |
| 56 | + expect(scriptTag).toHaveAttribute('data-domain', 'example.com'); |
| 57 | + expect(scriptTag).toHaveAttribute( |
| 58 | + 'src', |
| 59 | + 'https://plausible.example.com/js/script.js', |
| 60 | + ); |
| 61 | + expect(scriptTag).toHaveAttribute('defer'); |
| 62 | + }); |
58 | 63 | });
|
59 | 64 | });
|
0 commit comments