splide.test.js 1.4 KB

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