| 1 |
import { describe, expect, it } from 'vitest'; |
| 2 |
|
| 3 |
import Swup from '../../src/index.js'; |
| 4 |
import type { Options, Plugin } from '../../src/index.js'; |
| 5 |
import * as SwupTS from '../../src/Swup.js'; |
| 6 |
|
| 7 |
describe('Exports', () => { |
| 8 |
it('should export Swup', () => { |
| 9 |
const swup = new Swup(); |
| 10 |
expect(swup).toBeInstanceOf(Swup); |
| 11 |
}); |
| 12 |
|
| 13 |
it('should export Options type', () => { |
| 14 |
const options: Partial<Options> = { |
| 15 |
animateHistoryBrowsing: false, |
| 16 |
animationSelector: '[class*="transition-"]', |
| 17 |
cache: true, |
| 18 |
containers: ['#swup'], |
| 19 |
ignoreVisit: (url, { el } = {}) => !!el?.closest('[data-no-swup]'), |
| 20 |
linkSelector: 'a[href]', |
| 21 |
plugins: [], |
| 22 |
hooks: {}, |
| 23 |
resolveUrl: (url) => url, |
| 24 |
requestHeaders: { |
| 25 |
'X-Requested-With': 'swup', |
| 26 |
'Accept': 'text/html, application/xhtml+xml' |
| 27 |
}, |
| 28 |
skipPopStateHandling: (event) => event.state?.source !== 'swup' |
| 29 |
}; |
| 30 |
|
| 31 |
const swup = new Swup(options); |
| 32 |
expect(swup).toBeInstanceOf(Swup); |
| 33 |
}); |
| 34 |
|
| 35 |
it('should export Plugin type', () => { |
| 36 |
class SwupPlugin implements Plugin { |
| 37 |
name = 'SwupPlugin'; |
| 38 |
isSwupPlugin = true as const; |
| 39 |
mount = () => {}; |
| 40 |
unmount = () => {}; |
| 41 |
} |
| 42 |
|
| 43 |
const options: Partial<Options> = { |
| 44 |
plugins: [new SwupPlugin()] |
| 45 |
}; |
| 46 |
|
| 47 |
const swup = new Swup(options); |
| 48 |
expect(swup.plugins[0]).toBeInstanceOf(SwupPlugin); |
| 49 |
}); |
| 50 |
|
| 51 |
it('should only have a default export for UMD compatibility', () => { |
| 52 |
expect(Object.keys(SwupTS)).toEqual(['default']); |
| 53 |
}); |
| 54 |
}); |