Behaviors
#
DefinitionEach behavior consists in a set of "fixtures", which are handlers for specific requests.
The Mocks Server can handle multiple behaviors, so you can change the API responses at your convenience while the server is running.
#
Creating a behaviorFor creating a behavior, you have to use the mocks-server Behavior
class, providing an array of "fixtures" to it:
Read the "fixtures" code example to see how fixtures were defined first.
Save this file in the
mocks
folder in the root of your project.
Now, when loaded, the server will have available an "standard" behavior, which contains three fixtures.
#
Extending behaviorsBehaviors are extensibles, so, you can have an "standard" behavior, which defines the default behavior of the mock server and responses for all your api uris, and modify this behavior creating new ones that change only responses for certain uris. All extended behaviors are extensible as well.
You can add another one behavior extending the first one and changing only the response of the getUsers
fixture, for example:
Now, the server will have available "standard" and errorUpdatingUser
behaviors.
The errorUpdatingUser
behavior will send a different response only for the /api/users/:id
uri with PUT
method (supposing that updateUser
and errorUpdatingUser
have the same value for the url
and method
properties).