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