Behaviors
#
DefinitionEach behavior consists in a set of "fixtures", which are server responses for specific uris.
The Mocks Server can handle multiple behaviors, so you can change the API responses at your convenience just in a second.
#
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
behaviors
folder that you defined for your mocks-server when started.
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 mocks server and responses for all 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 for getUsers
, for example:
Now, 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
property).