feathers-mocha-utils
Utilities for testing a FeathersJS app with Mocha
Installation
npm install feathers-mocha-utils
Setting Up Your Project for Testing
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 before
and after
functions:
setup.js
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.
Assertion Utilities
Several assertion utilities are included. Check out example usage in the test file.
methodNotAllowed
requiresAuth
disableMultiItemChange
notImplemented
forbidden
notFound
canPatch
cannotPatch
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.js const todoServiceOnClient = feathersClient
Assertion APIs
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)
License
Copyright (c) 2017
Licensed under the MIT license.