There are two files:
requirejs-anonymous-define.html This is the mail file. It's an HTML file. It has two buttons: ### On Demand Require: On clicking this button, a library code is loaded using requirejs to print "On Demand require working" in the console. If we see that text in console, it means requrejs is working as expected ### Load Anonymous Define: On cliking this button, an external JS is loaded that is defined by the constant SCRIPT_HAVING_ANONYMOUS_DEFINE
anonymous-define.js This is an JS file that has a anonymous define that when loaded causes requirejs to throw error
- Load the page probably using http-server
- Should see the console log Page loaded
- Click on On Demand Require button. Should see console log of On Demand require working
- Click on Load Anonymous Define button. The file defined by SCRIPT_HAVING_ANONYMOUS_DEFINE const variable should get loaded and a console log Anonymous Define Loaded should be seen
- Click on On Demand Require button. Console error denoting anonymous define gets displayed
- Consequent click of On Demand Require works fine
This tool can be used to test that the file loaded using SCRIPT_HAVING_ANONYMOUS_DEFINE works fine without the anonymous define error.