-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Pass window object to mockPrototype #100
Conversation
Can it work? do your have tested it? |
When mocking the canvas on a non-global window object, the prototype mocks should apply to the same window object.
943fecd
to
9ac3cfb
Compare
@hustcc I added a test case in the latest revision. Is this what you had in mind? |
observationI am running into an issue when upgrading to
looking at the test case, it only covers when there is a wellformed window object. Not sure what the expected behavior when something other than a wellformed window object is; however I was not seeing the above error in currently failing line: https://github.com/hustcc/jest-canvas-mock/blob/master/src/mock/prototype.js#L37 ...
win.HTMLCanvasElement.prototype.getContext = getContext2D;
... suggestionsuggestion - update the code to have this change be more conditional where we check if the passed in drawbacks, this potentially might be masking something in a project where the user expects the browser to behave one way; and due to all this mocking abstraction it behaves differently during testing. I think this is acceptable since, we are already basically doing this now, it just will behave slightly differently with the proposed suggestion than it does now, so I wanted to call it out. |
Maybe I should revert the commit, @virtuoushub can help me do this? |
I don't think a revert is necessary, let me see if I can come up with a slightly modified implementation using my suggestion. fwiw, I opened a new issue over at #115 |
opened up a fix over at #116 |
When mocking the canvas on a non-global window object, the prototype
mocks should apply to the same window object.