Completed
Push — master ( 1719ac...509a65 )
by Jeroen De
10s
created

dationDispatcherCollection update method calls dispatchersꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
1
'use strict';
2
3
var test = require( 'tape' ),
4
	sinon = require( 'sinon' ),
5
	createValidationDispatcherCollection = require( '../lib/validation_dispatcher_collection' ).createValidationDispatcherCollection;
6
7
test( 'ValidationDispatcherCollection listens to store updates', function ( t ) {
8
	var storeSpy = {
9
			subscribe: sinon.spy()
10
		};
11
12
	createValidationDispatcherCollection( storeSpy, [], 'dummy' );
13
14
	t.ok( storeSpy.subscribe.calledOnce, 'mapper subscribes to store updates' );
15
	t.end();
16
} );
17
18
test( 'ValidationDispatcherCollection update method calls dispatchers', function ( t ) {
19
	var formContent = { amount: 42 },
20
		state = { donationForm: formContent },
21
		storeSpy = {
22
			subscribe: sinon.spy(),
23
			getState: sinon.stub().returns( state )
24
		},
25
		validatorSpy = { dispatchIfChanged: sinon.spy() },
26
		collection = createValidationDispatcherCollection( storeSpy, [ validatorSpy ], 'donationForm' );
27
28
	collection.onUpdate();
29
30
	t.ok( storeSpy.getState.calledOnce, 'onUpdate gets state from the store' );
31
	t.ok( validatorSpy.dispatchIfChanged.calledOnce, 'dispatchers are called' );
32
	t.ok( validatorSpy.dispatchIfChanged.calledWith( formContent, storeSpy ), 'dispatchers are called' );
33
	t.end();
34
} );
35
36