Jump to content
Search Community

jest mock gsap

mkahraman test
Moderator Tag

Recommended Posts

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();
				}
			}
		};
	};
};

 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...