{"action":"created","issue":{"url":"https://api.github.com/repos/christianalfoni/cerebral/issues/82","labels_url":"https://api.github.com/repos/christianalfoni/cerebral/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/christianalfoni/cerebral/issues/82/comments","events_url":"https://api.github.com/repos/christianalfoni/cerebral/issues/82/events","html_url":"https://github.com/christianalfoni/cerebral/issues/82","id":102972101,"number":82,"title":"How to test with Cerebral","user":{"login":"christianalfoni","id":3956929,"avatar_url":"https://avatars.githubusercontent.com/u/3956929?v=3","gravatar_id":"","url":"https://api.github.com/users/christianalfoni","html_url":"https://github.com/christianalfoni","followers_url":"https://api.github.com/users/christianalfoni/followers","following_url":"https://api.github.com/users/christianalfoni/following{/other_user}","gists_url":"https://api.github.com/users/christianalfoni/gists{/gist_id}","starred_url":"https://api.github.com/users/christianalfoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christianalfoni/subscriptions","organizations_url":"https://api.github.com/users/christianalfoni/orgs","repos_url":"https://api.github.com/users/christianalfoni/repos","events_url":"https://api.github.com/users/christianalfoni/events{/privacy}","received_events_url":"https://api.github.com/users/christianalfoni/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-08-25T08:05:40Z","updated_at":"2015-11-15T19:53:24Z","closed_at":"2015-09-12T09:20:49Z","body":"Hi,\r\n\r\nWe started a discussion on testing with Cerebral. There are multiple approaches here and I think we need to explore a bit more before setting a \"best convention\".\r\n\r\nHere are the approaches:\r\n\r\n### Test the signals as they are defined in the app\r\n\r\n```js\r\nimport controller from './path/to/cerebral/controller';\r\nimport './path/to/signal/to/test';\r\n\r\nit('should run the signal', function (done) {\r\n  const onEnd = function () {\r\n    expect(...);\r\n    done();\r\n  };\r\n  controller.once('signalEnd', onEnd);\r\n  controller.signals.somethingHappend({...});\r\n});\r\n```\r\n\r\nNow, this is more of an \"E2E\" test as you bring in a lot of your application into the test. It can not really be defined as a UNIT test. Also you will have a much harder time mocking out services etc. Tests will likely also leak into other tests as now they share the model layer.\r\n\r\n### Only test actions\r\n\r\n```js\r\nimport actionToTest from './path/to/action/to/test';\r\n\r\nit('should do something', function (done) {\r\n  const mockedInput = {};\r\n  const mockedState = {};\r\n  const mockedOutput = {};\r\n  const mockedServices = {};\r\n  \r\n  actionToTest(mockedInput, mockedState, mockedOutput, mockedServices);\r\n});\r\n```\r\nNow you have completely isolated tests and you can mock your brains out. You are also free to mock exactly what you need to test the specific action. \r\n\r\n### Summary\r\nSo my take on this is that you should not really test signals specifically. How they work will be tested through E2E tests, where you actually test interaction etc. By doing pure unit tests of each action you secure their functionality and they will break as soon as somebody changes any action, which is the point of UNIT tests. They avoid making changes without consideration.\r\n\r\nBut yeah, this is just my perspective :-)\r\n"},"comment":{"url":"https://api.github.com/repos/christianalfoni/cerebral/issues/comments/156846834","html_url":"https://github.com/christianalfoni/cerebral/issues/82#issuecomment-156846834","issue_url":"https://api.github.com/repos/christianalfoni/cerebral/issues/82","id":156846834,"user":{"login":"tnrich","id":2730609,"avatar_url":"https://avatars.githubusercontent.com/u/2730609?v=3","gravatar_id":"","url":"https://api.github.com/users/tnrich","html_url":"https://github.com/tnrich","followers_url":"https://api.github.com/users/tnrich/followers","following_url":"https://api.github.com/users/tnrich/following{/other_user}","gists_url":"https://api.github.com/users/tnrich/gists{/gist_id}","starred_url":"https://api.github.com/users/tnrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tnrich/subscriptions","organizations_url":"https://api.github.com/users/tnrich/orgs","repos_url":"https://api.github.com/users/tnrich/repos","events_url":"https://api.github.com/users/tnrich/events{/privacy}","received_events_url":"https://api.github.com/users/tnrich/received_events","type":"User","site_admin":false},"created_at":"2015-11-15T19:53:24Z","updated_at":"2015-11-15T19:53:24Z","body":"Hmm @garth , I'm not quite getting it. So inside of execSignal, you use something like model.tree.set({newStateHere}) ? Can you show the code where you're actually resetting the state? Thanks for all the examples by the way!"}}