|
| 1 | +import{mountSuspended}from'@nuxt/test-utils/runtime' |
| 2 | +import{beforeEach,describe,expect,it,vi}from'vitest' |
| 3 | +importScriptGoogleAdsensefrom'../../packages/script/src/runtime/components/ScriptGoogleAdsense.vue' |
| 4 | + |
| 5 | +constmocks=vi.hoisted(()=>({ |
| 6 | +status: {__v_isRef: true,value: 'loaded'}, |
| 7 | +useScriptGoogleAdsense: vi.fn(), |
| 8 | +useScriptTriggerElement: vi.fn(()=>()=>{}), |
| 9 | +})) |
| 10 | + |
| 11 | +vi.mock('../../packages/script/src/runtime/composables/useScriptTriggerElement',()=>({ |
| 12 | +useScriptTriggerElement: mocks.useScriptTriggerElement, |
| 13 | +})) |
| 14 | + |
| 15 | +vi.mock('../../packages/script/src/runtime/registry/google-adsense',()=>({ |
| 16 | +useScriptGoogleAdsense: mocks.useScriptGoogleAdsense, |
| 17 | +})) |
| 18 | + |
| 19 | +describe('google adsense component',()=>{ |
| 20 | +beforeEach(()=>{ |
| 21 | +vi.clearAllMocks() |
| 22 | +mocks.useScriptGoogleAdsense.mockReturnValue({status: mocks.status}) |
| 23 | +window.adsbygoogle=[] |
| 24 | +}) |
| 25 | + |
| 26 | +it('renders the in-feed layout key on the ad unit',async()=>{ |
| 27 | +constwrapper=awaitmountSuspended(ScriptGoogleAdsense,{ |
| 28 | +props: { |
| 29 | +dataAdClient: 'ca-pub-123', |
| 30 | +dataAdSlot: '456', |
| 31 | +dataAdFormat: 'fluid', |
| 32 | +dataAdLayoutKey: '-6t+ed+2i-1n-4w', |
| 33 | +}, |
| 34 | +}) |
| 35 | + |
| 36 | +expect({ |
| 37 | +adUnit: wrapper.get('ins').attributes('data-ad-layout-key'), |
| 38 | +wrapper: wrapper.attributes('data-ad-layout-key'), |
| 39 | +}).toEqual({ |
| 40 | +adUnit: '-6t+ed+2i-1n-4w', |
| 41 | +wrapper: undefined, |
| 42 | +}) |
| 43 | +}) |
| 44 | +}) |
0 commit comments