splide.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { minimum } from '../data/html';
  2. import Splide from '../../src/js/splide';
  3. import { DEFAULTS } from '../../src/js/constants/defaults';
  4. import { COMPLETE } from '../../src/js/components';
  5. describe( 'Splide ', () => {
  6. beforeEach( () => {
  7. document.body.innerHTML = minimum;
  8. } );
  9. test( 'should find an element with the given selector.', () => {
  10. const splide = new Splide( '#splide', {}, COMPLETE );
  11. expect( splide.root.id ).toBe( 'splide' );
  12. } );
  13. test( 'should accept an element as a root on construction.', () => {
  14. const root = document.getElementById( 'splide' );
  15. const splide = new Splide( root, {}, COMPLETE );
  16. expect( splide.root.id ).toBe( 'splide' );
  17. } );
  18. test( 'should overwrite default options with a given ones on construction.', () => {
  19. const splide = new Splide( '#splide', { perPage: 3 }, COMPLETE );
  20. expect( splide.options ).toEqual( { ...DEFAULTS, perPage: 3 } );
  21. } );
  22. test( '"is" should verify if a given type is a current one.', () => {
  23. const splide = new Splide( '#splide', { type: 'loop' }, COMPLETE ).mount();
  24. expect( splide.is( 'slide' ) ).toBe( false );
  25. expect( splide.is( 'loop' ) ).toBe( true );
  26. } );
  27. test( 'should make a root element visible after mount.', () => {
  28. const root = document.getElementById( 'splide' );
  29. root.style.visibility = 'hidden';
  30. const splide = new Splide( root, {}, COMPLETE );
  31. expect( splide.root.style.visibility ).toBe( 'hidden' );
  32. splide.mount();
  33. expect( splide.root.style.visibility ).toBe( 'visible' );
  34. } );
  35. } );