issues with unit testing custom widgets
See original GitHub issueI made a simple widget cookiecutter that uses TypeScript instead of JS and I added some tools to also run unit tests and linting, but I’m having some trouble unit testing the widgets.
If I import from ./example I get the following error:
 karma start karma.config.ts --browsers Chrome --single-run --log-level error
Chrome 58.0.3029 (Mac OS X 10.12.5) ERROR
  Uncaught ReferenceError: jQuery is not defined
  at /var/folders/k5/5f8qb7191cngz3v79ky_w5w0005njt/T/karma-typescript-bundle-10566ag6ZN8l7ET5x.js:14458
Which basically tells me that jQuery is accessed as a global var somewhere but it’s undefined. I could actually find where it occurred:
if ( typeof define === "function" && define.amd ) {
		// AMD. Register as an anonymous module.
		define( [
			"jquery",
			"./mouse",
			"../keycode",
			"../version",
			"../widget"
		], factory );
	} else {
		// Browser globals
		factory( jQuery ); // THIS IS WHERE IT BREAKS
	}
I tried to remove all UI widgets from the index.js file within jupyer-js-widgets package and I don’t see the error anymore, which suggested that the UI widgets within the lib must require/import something that references jQuery as a global variable.
I also tried including jquery lib before I run all unit tests, but then I get another error:
Chrome 58.0.3029 (Mac OS X 10.12.5) ERROR
  Uncaught TypeError: Cannot read property 'mouse' of undefined
  at /var/folders/k5/5f8qb7191cngz3v79ky_w5w0005njt/T/karma-typescript-bundle-10687kQQBEOX5mCp5.js:13504
And that was due to $.ui.mouse, where $.ui seems to be undefined.
So I’m unsure how I could actually fix this.
Issue Analytics
- State:
 - Created 6 years ago
 - Comments:8 (4 by maintainers)
 

Top Related StackOverflow Question
Thanks. It would be interesting to me to try to iterate towards a common testing infrastructure, and that might uncover the issue. I’m out for a bit, but can look at this when I get back (and anyone else, feel free to take this up).
If you check, I just pushed some changes and completely removed babel, same issue though.