burger
Version:
A lightweight turbolinks friendly JavaScript library
60 lines (43 loc) • 1.51 kB
text/coffeescript
jest
.autoMockOff()
$ = require('jquery')
Component = require('../component')
Collection = require('../collection')
findChildren = require('../services/find-children')
class Stub extends Component
@register()
class OtherStub extends Component
@register()
describe 'Collection', ->
instance = undefined
beforeEach ->
element =
$("""
<div>
<div data-burger="OtherStub" data-name="Mark" data-ref="Burger"></div>
<div data-burger="Stub" data-name="Gabe">
<div data-burger="OtherStub" data-name="Gabe" data-ref="Burger"></div>
</div>
</div>
""")
children = findChildren(element)
instance = new Collection(children)
describe '#size', ->
it 'gives you the length of children', ->
expect(instance.size()).toEqual(3)
describe '#first', ->
it 'returns the first item in the collection', ->
expect(instance.first().name).toEqual('OtherStub')
describe '#where', ->
it 'can find by class name', ->
expect(instance.size()).toEqual(3)
filtered = instance.where(OtherStub)
expect(filtered.size()).toEqual(2)
it 'can find by data', ->
expect(instance.size()).toEqual(3)
filtered = instance.where({ name: 'Gabe' })
expect(filtered.size()).toEqual(2)
filtered = instance.where({ name: 'Mark' })
expect(filtered.size()).toEqual(1)
filtered = instance.where({ name: 'Gabe', ref: 'Burger' })
expect(filtered.size()).toEqual(1)