question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

issues with unit testing custom widgets

See original GitHub issue

I 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:open
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jasongroutcommented, Jun 7, 2017

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).

0reactions
rolandjitsucommented, May 26, 2017

If you check, I just pushed some changes and completely removed babel, same issue though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Help required]: How to write unit tests for custom widgets #3054
I am creating a custom ipywidget and using pytest framework for unit testing. I am able to mock the ipykernel.comm and use it...
Read more >
unit testing on custom widgets using Jest framework
Hi, I would like to write unit testing on my custom widgets using Jest framework.my custom widget consumes dojo,esri libraries.for example.
Read more >
Flutter — Custom widget testing & strategy | by Sree - Medium
It's so easy to create and test custom widgets in Flutter. Let's make a simple custom RaisedButton which accepts shape, padding, a title...
Read more >
Custom Text Input Widget Unit Test - YouTube
The Custom Text Input Widget Unit Test app adds an input widget to the app editor with addition functionality, that can be used...
Read more >
An introduction to widget testing - Flutter documentation
In the introduction to unit testing recipe, you learned how to test Dart classes using the test package. To test widget classes, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found