Skip to content

Instantly share code, notes, and snippets.

@radzserg
Last active February 23, 2022 15:46
Show Gist options
  • Select an option

  • Save radzserg/dd052b8ef861880cbfe924fa615f8c5d to your computer and use it in GitHub Desktop.

Select an option

Save radzserg/dd052b8ef861880cbfe924fa615f8c5d to your computer and use it in GitHub Desktop.
import socialAuth from "path/to/socialAuth";
export default class SocialLoginForm extends Component {
loginWithSocialAccount = (e: React.SyntheticEvent) => {
const dataProvider = e.target.dataset.provider
socialAuth.login(dataProvider);
};
render() {
const { price } = this.state;
return (
<div>
<button
data-provider="facebook"
onClick={this.loginWithSocialAccount}
>
Facebook
</button>
<button
data-provider="twitter"
onClick={this.loginWithSocialAccount}
>
Twitter
</button>
</div>
);
}
}
/*
Easy enough, but what’s wrong with this example. It has a hardcoded dependency.
And problems start when you try to test such a component.
*/
test("it should redirect me to Facebook Login page, when I click FB button", () => {
const page = shallow(<SocialLoginForm />);
const fbButton = component.find(“button”).first();
fbButton.simulate("click");
// How can we test that socialAuth.login("facebook") have been called ?
})
// the other problem that your test becomes integration since you need to
// integrate your component with another one. And socialAuth can have another
// dependency inside of it that you will need to care about.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment