{"_id":"angular-socket.io-mock","_rev":"3-254b7c41fe15e4070f4f8c3b6408941e","name":"angular-socket.io-mock","description":"Drop in Mock replacement for angular-socket-io","dist-tags":{"latest":"1.2.0"},"versions":{"1.2.0":{"name":"angular-socket.io-mock","description":"Drop in Mock replacement for angular-socket-io","version":"1.2.0","authors":[{"name":"Bryan Tong","email":"contact@nullivex.com","homepage":"https://www.nullivex.com"}],"keywords":["angular","socket.io","mock","test"],"devDependencies":{"jasmine-core":"^2.1.3","karma":"^0.12.9","karma-jasmine":"^0.3.2","karma-phantomjs-launcher":"^0.1.4"},"scripts":{"test":"karma start --single-run --browsers PhantomJS"},"gitHead":"058b5331ca89784830639f06bd216c3d5c3bea7a","_id":"angular-socket.io-mock@1.2.0","_shasum":"087c9c1c4828430c189cf81f58e3769fee5a5376","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.12.0","_npmUser":{"name":"nullivex","email":"contact@nullivex.com"},"maintainers":[{"name":"nullivex","email":"contact@nullivex.com"}],"dist":{"shasum":"087c9c1c4828430c189cf81f58e3769fee5a5376","tarball":"https://registry.npmjs.org/angular-socket.io-mock/-/angular-socket.io-mock-1.2.0.tgz","integrity":"sha512-c1QDzczP3LDU/yDL65fv41CEIZri/r+E7ZEcP3bMnzt+q/uAHwEg0fa5fXuDEGkS/C3gcgedipzZUOVHxYEbPg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDmSr82Q4ijcVj3v2aJcIcMiXvBKJa1iy0Ivc6kQZs0ogIgL41bV+hSSWTqH93d+wfPCgfEs4ReleRPnWRRuZEjT5c="}]},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/angular-socket.io-mock-1.2.0.tgz_1478051644792_0.07153344433754683"}}},"readme":"angular-socket.io-mock [![Build Status](https://travis-ci.org/nullivex/angular-socket.io-mock.png?branch=master)](https://travis-ci.org/nullivex/angular-socket.io-mock)\n======================\n\nMock Socket.io bindings for AngularJS, useful for testing as a drop in replacement for\nhttps://github.com/btford/angular-socket-io which allows testing against a fake server.\n\n## Usage\n\n### Standard usage\n\n* Make sure AngularJS is loaded prior to inclusion.\n\nkarma.conf.js\n```js\nmodule.exports = function(config) {\n  config.set({\n    files: [\n      {pattern: \"bower_components/angular-socket.io-mock.js\", included: false}\n    ]\n  })\n}\n```\n\n## With RequireJS\n\nIn all our projects we utilize RequireJS to use this test library with RequireJS is very simple. Just replace the entry\nthat points to the standard angular-socket-io with this library. Below is an example.\n\nmain.js\n```js\nrequire.config({\n  baseUrl: \"/base/js\",\n  shim: {\n    \"socketio\": {exports: \"io\"},\n    \"angular\": {exports: \"angular\"},\n    \"ng-socket-io\": [\"angular\",\"socketio\"],\n    \"ng-mocks\": [\"angular\"]\n  },\n  paths: {\n    \"angular\": \"/base/bower_components/angular/angular\",\n    \"socketio\": \"/base/bower_components/socket.io-client/dist/socket.io\",\n    \"ng-socket-io\": \"/base/bower_components/angular-socket.io-mock/angular-socket.io-mock\",\n    \"ng-mocks\": \"/base/bower_components/angular-mocks/angular-mocks\"\n  },\n  callback: window.__karma__.start\n})\n```\n\nYour bower.json should look something like this.\n\nbower.json\n```json\n{\n  \"name\": \"my-app\",\n  \"version\": \"0.0.1\",\n  \"dependencies\": {\n    \"angular\": \"latest\",\n    \"angular-socket-io\": \"latest\"\n  },\n  \"devDependencies\": {\n    \"socket.io-client\": \"latest\",\n    \"angular-mocks\": \"latest\",\n    \"angular-socket.io-mock\": \"latest\"\n  }\n}\n```\n\n### Example Test\n\nThis example uses Mocha Test as the testing framework and ChaiJS for the assertion library. It also uses RequireJS to\nload the environment.\n\ntest.js\n```js\ndefine([\"chai\",\"angular\",\"angular-mocks\",\"angular-socket-io\"],function(chai){\n  describe(\"Test Suite\",function(){\n    beforeEach(module(\"app\"))\n    it(\"should be using the mock ng-socket.io\",inject(function($rootScope,$controller){\n      var expect = chai.expect\n        , scope = $rootScope.$new()\n        , ctrl = $controller(\"MyController\",{$scope: scope})\n      expect(scope.save).to.be.a(\"function\")\n      expect(scope.items).to.be.a(\"array\")\n      expect(scope.items.length).to.equal(3)\n    }))\n  })\n})\n```\n\nMyController.js\n```js\ndefine([\"angular\",\"ng-socket-io\"],function(ng){\n  var app = ng.module(\"app\",[\"btford.socket-io\"])\n  app.controller(\"MyController\",[\"$scope\",\"socket\",function($scope,socket){\n    //load items now\n    $scope.items = []\n    socket.emit(\"loadItems\",{},function(res){\n      $scope.items = res.res\n    })\n    //setup functions\n    $scope.save = function(){}\n  }])\n})\n```\n\n### Example test using Jasmine\nTest.js\n```js\ndescribe('Controller: socketController', function () {\n\n    // load the controller's module\n    beforeEach(module('app'));\n\n    var socketController,\n      notify,\n      scope;\n\n    // Initialize the controller and a mock scope\n    beforeEach(inject(function ($controller, $rootScope, _notify_) {\n      scope = $rootScope.$new();\n      notify = _notify_;\n      socketController = $controller('socketController', {\n        $scope: scope\n      });\n\n    }));\n\n    it('The scope.items should change somehow', function() {\n      expect(scope.items.length).toEqual(0);\n      notify.receive('loadItems',{res: ['1','2','3']} )\n      expect(scope.items.length).toEqual(3);\n    });\n\n  });\n```\n\n```js\n'use strict';\n\nangular.module('app')\n  .controller('socketController', function ($scope, notify) {\n    // As first step to unit-test the socket, what we are\n    // going to do it is to try mocking an error, and changing\n    // a variable.\n    // This I hope it's easy enough to get started. It is not easy.\n\n\n    $scope.items = []\n    notify.on(\"loadItems\", function(res){\n      $scope.items = res.res\n    });\n  });\n```\n\n### Todo\n\n* Usage with sinon.js for spies\n* Mocking responses\n\n*Note* Please see https://github.com/btford/angular-socket-io for library usage.\n\n## Changelog\n\n### 1.2.0\n* Merge pull reuqest #10 adding a prefix and forward option\n* Update to latest dependencies\n* Publish on NPM\n\n### 1.1.1\n* Add `forward` support\n\n### 1.1.0\n* .receive will acknowledge any .emit events with a callback as the last parameter\n\n### 1.0.0\n* Upgraded to work with latest angular.\n* Use 0.1.0 with older versions of angularjs.\n* Add `once` support\n\n### 0.1.0\n* Fixed issue interface with the latest angular package.\n\n### 0.0.1\n* Initial Release\n","maintainers":[{"name":"nullivex","email":"contact@nullivex.com"}],"time":{"modified":"2022-06-13T02:57:45.774Z","created":"2016-11-02T01:54:06.636Z","1.2.0":"2016-11-02T01:54:06.636Z"},"keywords":["angular","socket.io","mock","test"],"readmeFilename":"README.md"}