Utilities for testing a FeathersJS app with Mocha
npm install feathers-mocha-utils
Before every test, the Feathers server needs to be running. After all tests are complete, the server should close for the Node process to terminate. You can create a setup utility in your local project to easily accomplish this with Mocha's
const app =let server
Require this file at the top of every test, and it will take care of making sure the server starts and stops when it's time.
Several assertion utilities are included. Check out example usage in the test file.
All of the assertion utilities are in the
assert attribute of the default export. Here's an example of how to use the
assert.requiresAuth util. The example assumes you have a
/todos service that requires authentication for every method.
// Start the server before tests run and close on finishconst utils =const app = // path to app.jsconst feathersClient = // path to feathers-client.jsconst todoServiceOnClient = feathersClient
utils.assert.methodNotAllowed(service, method, done)
utils.assert.requiresAuth(service, method, done)
utils.assert.disableMultiItemChange(service, method, done)
utils.assert.notImplemented(service, method, done)
utils.assert.forbidden(service, method, done)
utils.assert.notFound(service, method, done)
utils.assert.canPatch(service, recordToPatch, attributeToPatch, newValue, done)
utils.assert.cannotPatch(service, recordToPatch, attributeToPatch, newValue, errorClassName, errorMessage, done)
Copyright (c) 2017
Licensed under the MIT license.