UNPKG

1.39 kBJavaScriptView Raw
1var test = require('tape')
2 , {{PascalName}}Step = require('./step.js')
3 , sinon = require('sinon')
4 , _ = require('lodash')
5 , defaultOptions = {}
6 , createView = function createView(options){
7 return new {{PascalName}}Step(_.defaults(options || {}, defaultOptions))
8 }
9 , stopListening
10 , setup = function setup(){
11 stopListening = sinon.spy({{PascalName}}Step.prototype, 'stopListening')
12 }
13 , cleanup = function cleanup(){
14 stopListening.restore()
15 }
16
17test('Step: {{PascalName}}: constructor', function constructorTest(t){
18 var view = createView()
19
20 t.equal(
21 typeof view
22 , 'object'
23 , 'creates an object'
24 )
25
26 t.end()
27})
28
29test('Step: {{PascalName}}#bindEvents', function bindEventsTest(t){
30 var view = createView()
31 , fn = view.bindEvents
32
33 setup()
34
35 // call bind events
36 fn.call(view)
37 t.equal(
38 stopListening.callCount
39 , 1
40 , 'calls stopListening so that events aren\'t bound multiple times'
41 )
42 t.ok(
43 stopListening.calledWith(view.state)
44 , 'calls stopListening with the state so that not all listeners are removed'
45 )
46
47 cleanup()
48 t.end()
49})
50
51test('Step: {{PascalName}}#beforeInit', function beforeInitTest(t){
52 var view = createView()
53 , fn = view.beforeInit
54 , options = defaultOptions
55
56 fn.call(view, options)
57 t.ok(
58 view.state instanceof view.State
59 , 'creates a state model'
60 )
61
62 t.end()
63})