-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TS and Cypress compatibility issues #13
Comments
Thanks for pointing out that issue! I recently published some fixes but forgot to upgrade the dependencies in the example, just merged #14 to fix that. I also use Cypress with TypeScript and need to get around to publishing some types for this package. Until then I think adding the following declaration to declare global {
namespace Cypress {
interface Chainable {
matchImageSnapshot: (options? : any) => void;
}
}
} |
Thanks for the feedback! I get |
Interesting, I did have a couple of issues setting up TypeScript with Cypress that were resolved by a combination of That said our TypeScript environments could be different. It might help to see if you can get any custom command working, something like: declare global {
namespace Cypress {
interface Chainable {
getTypeScriptWorking: typeof getTypeScriptWorking;
}
}
}
function getTypeScriptWorking() {
console.log('It works!');
}
Cypress.Commands.add('getTypeScriptWorking', getTypeScriptWorking); And then try adding |
Yeah so calling declare global TS doesn't like that. I can run custom commands using // tslint:disable-next-line:no-namespace
declare namespace Cypress {
// tslint:disable-next-line interface-name
interface Chainable {
foo: () => string
}
} But still doesn't fix trying to import in that file. |
I am gonna close this as this is potentially on cypress or my env. Would be nice to have a milestone for type defs. |
To get it to work, I ended up adding this file to my custom types directory import Cypress from 'cypress';
declare global {
namespace Cypress {
interface Chainable {
matchImageSnapshot: (options?: any) => void;
}
}
} Then in {
...
"files": [
"types/cypress-image-snapshot/index.d.ts"
]
} And if you have import Cypress from 'cypress';
import { MatchImageSnapshotOptions } from 'jest-image-snapshot';
declare global {
namespace Cypress {
interface MatchImageSnapshotOptions extends MatchImageSnapshotOptions, Partial<ScreenshotOptions> {}
interface Chainable {
matchImageSnapshot(options?: MatchImageSnapshotOptions): void;
matchImageSnapshot(fileName: string, options?: MatchImageSnapshotOptions): void;
}
}
} Hopefully that helps someone 👍 |
Went with the jest option. Works great. Cheers! |
I went ahead and added typings for folks to use: DefinitelyTyped/DefinitelyTyped#41222 Now, all you need to do is |
Having difficulty getting this working with the typescript variant of cypress. Also looks like the new version of cypress doesn't like you wrapping commands as the example errors out on run. Main problem I am getting is that there are no type defs and cypress is saying the snapshotmatching commands are not chainable off the cy namespace.
The text was updated successfully, but these errors were encountered: