spec_app/spec/javascripts/up/syntax_spec.js.coffee in unpoly-rails-0.24.1 vs spec_app/spec/javascripts/up/syntax_spec.js.coffee in unpoly-rails-0.25.0
- old
+ new
@@ -13,20 +13,33 @@
up.hello(affix('.container .child'))
expect(observeClass).not.toHaveBeenCalledWith('container')
expect(observeClass).toHaveBeenCalledWith('child')
- destructor = jasmine.createSpy('destructor')
- up.compiler '.child', ($element) ->
- destructor
-
- up.hello(affix('.container .child'))
- expect(destructor).not.toHaveBeenCalled()
-
- up.destroy('.container')
- expect(destructor).toHaveBeenCalled()
+ describe 'destructors', ->
+ it 'allows initializers to return a function that is called when the compiled element is removed', ->
+ destructor = jasmine.createSpy('destructor')
+ up.compiler '.child', ($element) ->
+ destructor
+
+ up.hello(affix('.container .child'))
+ expect(destructor).not.toHaveBeenCalled()
+
+ up.destroy('.container')
+ expect(destructor).toHaveBeenCalled()
+
+ it 'does not throw an error if both container and child have a destructor, and the container gets destroyed', ->
+ up.compiler '.container', ($element) ->
+ return (->)
+
+ up.compiler '.child', ($element) ->
+ return (->)
+
+ destruction = -> up.destroy('.container')
+ expect(destruction).not.toThrowError()
+
it 'parses an up-data attribute as JSON and passes the parsed object as a second argument to the initializer', ->
observeArgs = jasmine.createSpy()
up.compiler '.child', ($element, data) ->
observeArgs($element.attr('class'), data)
@@ -99,19 +112,19 @@
up.compiler '.element', { priority: 2 }, -> traces.push('bar')
up.compiler '.element', { priority: 0 }, -> traces.push('baz')
up.compiler '.element', { priority: 3 }, -> traces.push('bam')
up.compiler '.element', { priority: -1 }, -> traces.push('qux')
up.hello(affix('.element'))
- expect(traces).toEqual ['qux', 'baz', 'foo', 'bar', 'bam']
+ expect(traces).toEqual ['bam', 'bar', 'foo', 'baz', 'qux']
it 'considers priority-less compilers to be priority zero', ->
traces = []
up.compiler '.element', { priority: 1 }, -> traces.push('foo')
up.compiler '.element', -> traces.push('bar')
up.compiler '.element', { priority: -1 }, -> traces.push('baz')
up.hello(affix('.element'))
- expect(traces).toEqual ['baz', 'bar', 'foo']
+ expect(traces).toEqual ['foo', 'bar', 'baz']
it 'runs two compilers with the same priority in the order in which they were registered', ->
traces = []
up.compiler '.element', { priority: 1 }, -> traces.push('foo')
up.compiler '.element', { priority: 1 }, -> traces.push('bar')
@@ -124,20 +137,45 @@
traces = []
up.compiler '.element', { priority: 10 }, -> traces.push('foo')
up.compiler '.element', { priority: -1000 }, -> traces.push('bar')
up.macro '.element', -> traces.push('baz')
up.hello(affix('.element'))
- expect(traces).toEqual ['baz', 'bar' , 'foo']
+ expect(traces).toEqual ['baz', 'foo' , 'bar']
it 'allows to macros to have priorities of their own', ->
traces = []
up.macro '.element', { priority: 1 }, -> traces.push('foo')
up.macro '.element', { priority: 2 }, -> traces.push('bar')
up.macro '.element', { priority: 0 }, -> traces.push('baz')
up.macro '.element', { priority: 3 }, -> traces.push('bam')
up.macro '.element', { priority: -1 }, -> traces.push('qux')
+ up.compiler '.element', { priority: 999 }, -> traces.push('ccc')
up.hello(affix('.element'))
- expect(traces).toEqual ['qux', 'baz', 'foo', 'bar', 'bam']
+ expect(traces).toEqual ['bam', 'bar', 'foo', 'baz', 'qux', 'ccc']
+
+ it 'runs two macros with the same priority in the order in which they were registered', ->
+ traces = []
+ up.macro '.element', { priority: 1 }, -> traces.push('foo')
+ up.macro '.element', { priority: 1 }, -> traces.push('bar')
+ up.hello(affix('.element'))
+ expect(traces).toEqual ['foo', 'bar']
+
+ it 'allows users to use the built-in [up-expand] from their own macros', ->
+ up.macro '.element', ($element) ->
+ $element.attr('up-expand', '')
+ $element = affix('.element a[href="/foo"][up-target=".target"]')
+ up.hello($element)
+ expect($element.attr('up-target')).toEqual('.target')
+ expect($element.attr('up-href')).toEqual('/foo')
+
+ it 'allows users to use the built-in [up-dash] from their own macros', ->
+ up.macro '.element', ($element) ->
+ $element.attr('up-dash', '.target')
+ $element = affix('a.element[href="/foo"]')
+ up.hello($element)
+ expect($element.attr('up-target')).toEqual('.target')
+ expect($element.attr('up-preload')).toEqual('')
+ expect($element.attr('up-instant')).toEqual('')
describe 'up.hello', ->
it 'should have tests'
\ No newline at end of file