{"library":"protractor-http-mock","title":"Protractor HTTP Mocking","description":"Protractor HTTP Mock provides a NodeJS module designed to facilitate mocking HTTP calls within Protractor end-to-end tests, specifically for AngularJS applications. Its core function is to allow developers to isolate UI and client-side application code by intercepting and responding to network requests with predefined data, thus removing dependencies on external APIs during test execution. A key differentiator is its independence from Angular Mocks (ngMockE2E), meaning it does not require any modifications to the AngularJS application under test. The current stable version, 0.10.0, was released in 2017. Due to its tight coupling with Protractor, which was officially deprecated in 2022, `protractor-http-mock` is effectively an abandoned package with no ongoing development or maintenance.","language":"javascript","status":"abandoned","last_verified":"Wed Apr 22","install":{"commands":["npm install protractor-http-mock"],"cli":null},"imports":["const mock = require('protractor-http-mock');","require('protractor-http-mock').config = { rootDirectory: __dirname, protractorConfig: 'my-protractor-config.conf' };","mock.teardown();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const mock = require('protractor-http-mock');\nconst path = require('path');\n\nexports.config = {\n  directConnect: true,\n  capabilities: {\n    'browserName': 'chrome'\n  },\n  framework: 'jasmine',\n  specs: [path.resolve(__dirname, 'mock.spec.js')],\n  onPrepare: function() {\n    require('protractor-http-mock').config = {\n      rootDirectory: __dirname,\n      protractorConfig: 'protractor.conf.js', // Or the actual name of this config file\n      mocks: {\n        default: ['mock-login'],\n        dir: 'mocks'\n      }\n    };\n  }\n};\n\n// mock.spec.js (in the same directory, or specified in specs)\n\ndescribe('Protractor HTTP Mock Example', function() {\n  beforeEach(function() {\n    mock.setup(); // Ensure mocks are cleared and ready for each test\n  });\n\n  afterEach(function() {\n    mock.teardown();\n  });\n\n  it('should mock a GET request for user data', function() {\n    mock([\n      {\n        request: {\n          path: '/api/users/1',\n          method: 'GET'\n        },\n        response: {\n          data: {\n            userName: 'Mocked User',\n            email: 'mock@example.com'\n          },\n          status: 200\n        }\n      }\n    ]);\n\n    // Assume your app navigates to a page that makes this request\n    browser.get('http://localhost:8000/app/#/users/1'); \n\n    // Example: Verify UI reflects mocked data (replace with actual selectors)\n    element(by.id('username-display')).getText().then(function(text) {\n      expect(text).toEqual('Mocked User');\n    });\n    element(by.id('email-display')).getText().then(function(text) {\n      expect(text).toEqual('mock@example.com');\n    });\n  });\n\n  it('should load mocks from a file', function() {\n    // Create a file: mocks/products.js\n    // module.exports = [{ request: { path: '/api/products', method: 'GET' }, response: { data: [{id: 1, name: 'Mock Product'}] } }];\n    mock(['products']); // Loads from mocks/products.js relative to rootDirectory\n    browser.get('http://localhost:8000/app/#/products');\n    // Assert that products are loaded from mock\n  });\n});\n","lang":"javascript","description":"This quickstart demonstrates configuring `protractor-http-mock` in a Protractor configuration file, defining an inline HTTP mock, and loading a mock from an external file within a test spec. It also shows the essential `setup` and `teardown` calls in `beforeEach` and `afterEach` hooks.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}