javascript - Testing a React component - determining where the functionality should be tested -
i extremely new testing in general, not react testing, i'm still trying figure out not how test, what test.
here login
callback gets called on submit of form:
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(); },
authmodel
backbone.js model. question, lets it's external module i'm importing login.jsx
component.
i'm writing test see if username typed, authmodel.login()
gets called. want test in test.login.js
test file, test in test.authmodel.js
test file?
it('calls login when there\'s username present', () => { react.finddomnode(loginelement.refs.username).value = 'foo'; testutils.simulate.submit(form); // not sure direction take test });
current test (in test.login.js
) context...
any advice appreciated, said, genuinely first testing i've ever done.
sounds want spy. stub out real implementation of authmodel , replace object can make expectations against:
spyon(authmodel, 'login'); // trigger login somehow expect(authmodel.login).tohavebeencalled();
or if want test arguments passed:
expect(authmodel.login).tohavebeencalledwith('username', 's3cretpassw0rd);
Comments
Post a Comment