1 | {MockNode} = require('../lib/karen')
|
2 |
|
3 | describe 'MockNode', ->
|
4 | def 'node', -> new MockNode
|
5 |
|
6 | describe '#style', ->
|
7 | it 'allows for read/write styles', ->
|
8 | @node.style.background = 'red';
|
9 | @node.style.background.should.equal('red')
|
10 |
|
11 | describe '#appendChild', ->
|
12 | it 'emits append-child event with node as argument', (done) ->
|
13 | child = {}
|
14 | @node.on 'append-child', (node) ->
|
15 | done() if node == child
|
16 | @node.appendChild(child)
|
17 |
|
18 | describe '#removeChild', ->
|
19 | it 'emits remove-child event with node when child has been added', (done) ->
|
20 | node = {}
|
21 | @node.on 'remove-child', (child) ->
|
22 | done() if child == node
|
23 | @node.appendChild(node)
|
24 | @node.removeChild(node)
|
25 |
|
26 | it 'does not emit remove-child event when child has not been added', (done) ->
|
27 | node = {}
|
28 | @node.on 'remove-child', ->
|
29 | done('should not have emit event, but did')
|
30 | @node.removeChild(node)
|
31 | done()
|
32 |
|
33 | describe '#getAttribute/#setAttribute', ->
|
34 | it 'allows to read and write attributes', ->
|
35 | @node.setAttribute('foo', 'bar')
|
36 | @node.setAttribute('baz', 'qux')
|
37 | @node.getAttribute('foo').should.equal('bar')
|
38 | @node.getAttribute('baz').should.equal('qux')
|
39 |
|
40 | describe 'getBoundingClientRect', ->
|
41 | beforeEach ->
|
42 | @boundingClientRect = @node.getBoundingClientRect()
|
43 |
|
44 | describe '#height', ->
|
45 | it 'returns node height', ->
|
46 | @boundingClientRect.height.should.equal(0)
|
47 |
|
48 | describe '#width', ->
|
49 | it 'returns node width', ->
|
50 | @boundingClientRect.width.should.equal(0)
|
51 |
|
52 | describe '#left', ->
|
53 | it 'returns node left', ->
|
54 | @boundingClientRect.left.should.equal(0)
|
55 |
|
56 | describe '#bottom', ->
|
57 | it 'returns node bottom', ->
|
58 | @boundingClientRect.bottom.should.equal(0)
|
59 |
|
60 | describe '#right', ->
|
61 | it 'returns node right', ->
|
62 | @boundingClientRect.right.should.equal(0)
|
63 |
|
64 | describe '#top', ->
|
65 | it 'returns node top', ->
|
66 | @boundingClientRect.top.should.equal(0)
|
67 |
|
68 | describe '#ownerDocument', ->
|
69 | it 'returns a MockDocument object', ->
|
70 | @node.ownerDocument.should.be.an('object')
|
71 |
|
72 | it 'returns same owner document every time', ->
|
73 | @node.ownerDocument.should.equal(@node.ownerDocument)
|
74 |
|
75 | describe '#parentNode', ->
|
76 | it 'returns a MockNode object', ->
|
77 | @node.parentNode.should.be.an('object')
|
78 |
|
79 | it 'returns same parent every time', ->
|
80 | @node.parentNode.should.equal(@node.parentNode)
|
81 |
|
82 | describe '#getElementsByTagName', ->
|
83 | it 'returns an empty array', ->
|
84 | @node.getElementsByTagName('div').should.eql([])
|
85 |
|
86 | describe '#insertBefore', ->
|
87 | it 'does nothing but exist', ->
|
88 | @node.insertBefore({})
|