javascript - Handling WebSocket connections in Jasmine tests -
i have test.login.js
:
it('calls login when there\'s username present', () => { react.finddomnode(loginelement.refs.username).value = 'foo'; testutils.simulate.submit(form); expect(loginelement.state.errored).toequal(false); });
by submitting form, calls login method:
login() { let typedusername = react.finddomnode(this.refs.username).value; if (!typedusername) { return this.setstate({ errored: true }); } // don't send request here, set username on authmodel , call `login` method below authmodel.set('username', typedusername); authmodel.login(); },
so i'm trying test functionality of login.jsx
, not authmodel.js
, calling authmodel.login()
, sends message on websocket. however, issue in actual app, don't load until websocket has connected (i fire event render react app), in jasmine test, don't wait event, receive:
error: null, domexception{stack: 'error: failed execute 'send' on 'websocket': still in connecting state.
and test fails, which, shouldn't fail because it's encapsulated functionality want to. errors further dependency tree.
what best approach either working around this, or mitigate websocket trying connect in test env? (i'm extremely new testing, these concepts alien me right now)
i won't pretend know lot this, can't dependency inject authmodel how , mock in tests? sorry isn't complete answer it's first instinct be.
if need library assist this, angular/di (from angular2) pretty great.
Comments
Post a Comment