Skip to content

Commit

Permalink
test: lib/connect.js replication error
Browse files Browse the repository at this point in the history
Adding test for lib/connect.js replication error.
  • Loading branch information
capellini committed Jul 6, 2017
1 parent 22a0827 commit 8c76904
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/unit/connect-test.js
Expand Up @@ -59,3 +59,35 @@ test('connect with remote being promise', function (t) {

t.end()
})

test('connect replication error', function (t) {
t.plan(3)

var syncApi = {
on: simple.stub()
}
var state = {
emitter: {
emit: simple.stub()
},
remote: 'remoteDb',
db: {
sync: simple.stub()
}
}
simple.mock(state.db, 'sync').returnWith(syncApi)

connect(state)

.then(function () {
t.is(syncApi.on.calls[0].args[0], 'error', 'listens "error" event')

var errorCallback = syncApi.on.calls[0].args[1]
var error = new Error('Replication error')

errorCallback(error)

t.is(state.emitter.emit.lastCall.args[0], 'error', 'last event emitted was an error event')
t.is(state.emitter.emit.lastCall.args[1], error, 'error event was called with error object')
})
})

0 comments on commit 8c76904

Please sign in to comment.