mkahraman Posted April 13, 2020 Share Posted April 13, 2020 I am trying to mock gsap on react.js, CRA. (gsap 3.2.6) Not sure why this is not working __mocks__ ----gsap.js ----Draggable.js import {gsap} from 'gsap'; import {Draggable} from 'gsap/Draggable'; gsap.registerPlugin(Draggable); //__mocks__/gsap/gsap.js module.exports = () => { return function() { return { gsap: class { static to(selector, options) { return jest.fn(); } static set(selector, options) { return jest.fn(); } static registerPlugin(plugin) { return jest.fn(); } }, TweenLite: { set: function() {}, to: function() {} } }; }; }; //__mocks__/Draggable.js module.exports = () => { return function() { return { Draggable: { create: function() { return 123; }, onDragEnd: function() { return jest.fn(); } } }; }; }; 1 Link to comment Share on other sites More sharing options...
ZachSaucier Posted April 13, 2020 Share Posted April 13, 2020 Hey mkahraman. This sounds like a question for mocks, whatever that is. It would be really helpful if you recreated the error that you're getting using CodeSandbox or StackBlitz as this thread covers: 1 Link to comment Share on other sites More sharing options...
Nasr Galal Posted August 4, 2020 Share Posted August 4, 2020 I have used your attached code, but when you use a plugin, sometimes it throws this: FAIL tests/unit/components/diagram.spec.ts ● Test suite failed to run TypeError: Cannot read property 'registerPlugin' of undefined Link to comment Share on other sites More sharing options...
ZachSaucier Posted August 4, 2020 Share Posted August 4, 2020 22 minutes ago, Nasr Galal said: I have used your attached code, but when you use a plugin, sometimes it throws this Sounds like GSAP is failing to load before your code is ran. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now