{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/5561","labels_url":"https://api.github.com/repos/meteor/meteor/issues/5561/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/5561/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/5561/events","html_url":"https://github.com/meteor/meteor/pull/5561","id":113964212,"number":5561,"title":"Adds Meteor.stubMethods and Meteor.unstubMethods","user":{"login":"Sanjo","id":727955,"avatar_url":"https://avatars.githubusercontent.com/u/727955?v=3","gravatar_id":"","url":"https://api.github.com/users/Sanjo","html_url":"https://github.com/Sanjo","followers_url":"https://api.github.com/users/Sanjo/followers","following_url":"https://api.github.com/users/Sanjo/following{/other_user}","gists_url":"https://api.github.com/users/Sanjo/gists{/gist_id}","starred_url":"https://api.github.com/users/Sanjo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sanjo/subscriptions","organizations_url":"https://api.github.com/users/Sanjo/orgs","repos_url":"https://api.github.com/users/Sanjo/repos","events_url":"https://api.github.com/users/Sanjo/events{/privacy}","received_events_url":"https://api.github.com/users/Sanjo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:DDP","name":"Project:DDP","color":"c7def8"},{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:Testing","name":"Project:Testing","color":"207de5"},{"url":"https://api.github.com/repos/meteor/meteor/labels/ready-for-review","name":"ready-for-review","color":"e6e6e6"}],"state":"open","locked":false,"assignee":{"login":"stubailo","id":448783,"avatar_url":"https://avatars.githubusercontent.com/u/448783?v=3","gravatar_id":"","url":"https://api.github.com/users/stubailo","html_url":"https://github.com/stubailo","followers_url":"https://api.github.com/users/stubailo/followers","following_url":"https://api.github.com/users/stubailo/following{/other_user}","gists_url":"https://api.github.com/users/stubailo/gists{/gist_id}","starred_url":"https://api.github.com/users/stubailo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stubailo/subscriptions","organizations_url":"https://api.github.com/users/stubailo/orgs","repos_url":"https://api.github.com/users/stubailo/repos","events_url":"https://api.github.com/users/stubailo/events{/privacy}","received_events_url":"https://api.github.com/users/stubailo/received_events","type":"User","site_admin":false},"milestone":null,"comments":13,"created_at":"2015-10-29T02:14:44Z","updated_at":"2015-11-04T22:47:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/meteor/meteor/pulls/5561","html_url":"https://github.com/meteor/meteor/pull/5561","diff_url":"https://github.com/meteor/meteor/pull/5561.diff","patch_url":"https://github.com/meteor/meteor/pull/5561.patch"},"body":"### Intro\r\n\r\nThis addition enables developers to unit test code that call Meteor methods in a simple way.\r\n\r\nThe pull request adds two methods: `Meteor.stubMethods` and `Meteor.unstubMethods`. Both are intended to be used in client unit test code. `Meteor.stubMethods` ca replaced the method implementation a method with a fake implementation.\r\n\r\n### Example\r\n\r\nThe added unit tests in this pull request show how use the API.\r\n\r\nIn addition here is an example of an scenario where you would use those methods.\r\n\r\nApp code:\r\n```js\r\nApp.Services.MyService = {\r\n  myMethod: function() {\r\n    Meteor.call('myMethod', function(error, result) {\r\n      if (!error) {\r\n        Session.set('theResult', result);\r\n      } else {\r\n        Session.set('theResult', 'Error!');\r\n      }\r\n    });\r\n  }\r\n}\r\n```\r\n\r\nTest:\r\n```js\r\ndescribe('MyService', function() {\r\n  describe('myMethod', function() {\r\n    afterEach(function() {\r\n      Meteor.unstubMethods(['myMethod']);\r\n    });\r\n\r\n    it('sets the result in the session when there is no error', function() {\r\n      Meteor.stubMethods({\r\n        'myMethod': function () {\r\n          return 'noErrorResult';\r\n        });\r\n      });\r\n      spyOn(Session, 'set');\r\n      App.Services.MyService.myMethod();\r\n      expect(Session.set).toHaveBeenCalledWith('theResult', 'noErrorResult');\r\n    });\r\n\r\n    it('does not set the result in the session when there is an error', function() {\r\n      Meteor.stubMethods({\r\n        'myMethod': function () {\r\n          throw new Error('Oh no');\r\n        });\r\n      });\r\n      spyOn(Session, 'set');\r\n      App.Services.MyService.myMethod();\r\n      expect(Session.set).toHaveBeenCalledWith('theResult', 'Error!');\r\n    });\r\n  });\r\n});\r\n```\r\n\r\n### Epilogue\r\n\r\nThis is one step into the direction of making Meteor app testing simple. Your constructive feedback is welcomed ;-)\r\n"},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/153894229","html_url":"https://github.com/meteor/meteor/pull/5561#issuecomment-153894229","issue_url":"https://api.github.com/repos/meteor/meteor/issues/5561","id":153894229,"user":{"login":"Sanjo","id":727955,"avatar_url":"https://avatars.githubusercontent.com/u/727955?v=3","gravatar_id":"","url":"https://api.github.com/users/Sanjo","html_url":"https://github.com/Sanjo","followers_url":"https://api.github.com/users/Sanjo/followers","following_url":"https://api.github.com/users/Sanjo/following{/other_user}","gists_url":"https://api.github.com/users/Sanjo/gists{/gist_id}","starred_url":"https://api.github.com/users/Sanjo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sanjo/subscriptions","organizations_url":"https://api.github.com/users/Sanjo/orgs","repos_url":"https://api.github.com/users/Sanjo/repos","events_url":"https://api.github.com/users/Sanjo/events{/privacy}","received_events_url":"https://api.github.com/users/Sanjo/received_events","type":"User","site_admin":false},"created_at":"2015-11-04T22:47:48Z","updated_at":"2015-11-04T22:47:48Z","body":"@stubailo Yes, doing it now. Can I introduce the Meteor.Testing namespace?"}}