elements.spec.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import $ from 'jquery';
  2. import elements from '../src/js/helpers/elements';
  3. jasmine.getStyleFixtures().fixturesPath = 'base/dist';
  4. jasmine.getFixtures().fixturesPath = 'base/test/fixtures';
  5. describe('Elements helper (elements.js) -> ', function() {
  6. beforeEach(function() {
  7. jasmine.getStyleFixtures().load = 'aos.css';
  8. jasmine.getFixtures().load('aos.fixture.html');
  9. });
  10. afterEach(function() {
  11. jasmine.getStyleFixtures().cleanUp();
  12. jasmine.getFixtures().cleanUp();
  13. });
  14. it('Should return array with objects that coresponds to elements in aos.fixture.html', function() {
  15. var aosElements = elements();
  16. expect(aosElements.length).toBe($('[data-aos]').length);
  17. });
  18. it('Should return array of objects', function() {
  19. var aosElements = elements();
  20. for (var i = 0; i < aosElements.length; i++) {
  21. if (aosElements[i].node) {
  22. expect(typeof aosElements[i]).toEqual('object');
  23. }
  24. }
  25. });
  26. it('Each object in returned array should have "node" attribute', function() {
  27. var aosElements = elements();
  28. for (var i = 0; i < aosElements.length; i++) {
  29. expect(aosElements[i].hasOwnProperty('node')).toBe(true);
  30. }
  31. });
  32. it('Each objects node in returned array should be a DOMNode', function() {
  33. var aosElements = elements();
  34. function isNode(obj) {
  35. return (typeof obj === "object") && (obj.nodeType === 1) && (typeof obj.style === "object") && (typeof obj.ownerDocument === "object");
  36. }
  37. for (var i = 0; i < aosElements.length; i++) {
  38. if (aosElements[i].node) {
  39. expect(isNode(aosElements[i].node)).toBe(true);
  40. }
  41. }
  42. });
  43. });