Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Created November 28, 2021 12:13
Show Gist options
  • Save jmaicaaan/4a3cf784587f742a0430ebb235b5685e to your computer and use it in GitHub Desktop.
Save jmaicaaan/4a3cf784587f742a0430ebb235b5685e to your computer and use it in GitHub Desktop.
Cypress.Commands.add('loginByFacebook', (
status: 'connected' | 'not_authorized' | 'unknown' = 'connected'
) => {
return cy.window().then((win) => {
const callbackResult = {
...status === 'connected' && {
status: 'connected',
authResponse: {
accessToken: 'test_fbAccessToken',
},
},
...status === 'not_authorized' && {
status: 'not_authorized',
},
...status === 'unknown' && {
status: 'unknown',
},
};
if (!win.FB) {
return;
}
win.FB = {
...win.FB,
login: (callback: (response: unknown) => {}) => {
callback(callbackResult);
},
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment