Skip to content

Commit

Permalink
test: feathers-client mocks call cb function
Browse files Browse the repository at this point in the history
This prevents the milliion “uncaught exception” errors that happen 5 seconds after the tests finish.
  • Loading branch information
marshallswain committed Oct 29, 2020
1 parent 613b16a commit 8d399fa
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions test/fixtures/feathers-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,50 @@ const baseUrl = 'http://localhost:3030'

// These are fixtures used in the service-modulet.test.js under socket events.
let id = 0
mockServer.on('things::create', function (data) {
mockServer.on('things::create', function (data, params, cb) {
data.id = id
id++
mockServer.emit('things created', data)
cb(null, data)
})
mockServer.on('things::patch', function (id, data) {
mockServer.on('things::patch', function (id, data, params, cb) {
Object.assign(data, { id, test: true })
mockServer.emit('things patched', data)
cb(null, data)
})
mockServer.on('things::update', function (id, data) {
mockServer.on('things::update', function (id, data, params, cb) {
Object.assign(data, { id, test: true })
mockServer.emit('things updated', data)
cb(null, data)
})
mockServer.on('things::remove', function (id) {
mockServer.emit('things removed', { id, test: true })
mockServer.on('things::remove', function (id, obj, cb) {
const response = { id, test: true }
mockServer.emit('things removed', response)
cb(null, response)
})

let idDebounce = 0

mockServer.on('things-debounced::create', function (data) {
mockServer.on('things-debounced::create', function (data, obj, cb) {
data.id = idDebounce
idDebounce++
mockServer.emit('things-debounced created', data)
cb(null, data)
})
mockServer.on('things-debounced::patch', function (id, data) {
mockServer.on('things-debounced::patch', function (id, data, params, cb) {
Object.assign(data, { id, test: true })
mockServer.emit('things-debounced patched', data)
cb(null, data)
})
mockServer.on('things-debounced::update', function (id, data) {
mockServer.on('things-debounced::update', function (id, data, params, cb) {
Object.assign(data, { id, test: true })
mockServer.emit('things-debounced updated', data)
cb(null, data)
})
mockServer.on('things-debounced::remove', function (id) {
mockServer.emit('things-debounced removed', { id, test: true })
mockServer.on('things-debounced::remove', function (id, params, cb) {
const response = { id, test: true }
mockServer.emit('things-debounced removed', response)
cb(null, response)
})

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
Expand Down

0 comments on commit 8d399fa

Please sign in to comment.