A wrapper around protractor-http-mock to make it a Protractor plugin.
- Allows configuration as a Protractor plugin
- Provides user-friendly errors and instructions
- Can be run inside or outside specs with the same results
See example for more information on usage.
exports.config = {
// ... the rest of your config
plugins: [
{
package: 'protractor-http-mock-plugin',
// This is passed through to protractor-http-mock.
// Example copied from https://github.com/atecarlos/protractor-http-mock/
mocks: {
// For consistent results, use an absolute path for dir.
// E.g. for a folder sibling to this config file:
// dir: path.join(__dirname, 'my-mocks')
dir: 'my-mocks',
default: ['default']
},
httpMockPlugins: {
default: ['protractor-http-mock-sample-plugin']
}
}
]
};
Mocks can be inline objects or string references to files in the mocks dir defined above.
As files, mocks can be any requireable file: .json
, or .js
that exports an array.
See protractor-http-mock for more mock examples.
describe('My suite', function () {
mocks.load([
'a-mock-filename'
]);
it('should use the mocks', function () {
// test code here
});
});
my-mocks/default.json
[
{
"request": {
"method": "POST",
"path": "/default"
},
"response": {
"data": {
"message": "This is a default response"
}
}
}
]
my-mocks/a-mock-filename.js
module.exports = [
{
"request": {
"method": "POST",
"path": "/error"
},
"response": {
"status": 401
}
}
]
cd example && bower install
(requires bower)npm run server
in a separate shell to run the example appnpm test