Using react-testing-library without global-jsdom - react-testing-library

I want to be able to setup specific instances of window and document for use by render(). I can specify the container by creating a specific instance of jsdom thus:
this.dom = new JSDOM('<body></body>')
const container = this.document().createElement('div')
render(
<Provider store={store}>
<MyComponent />
</Provider>,
{ container: this.dom.window.document.body.appendChild(container) }
)
If I remove global-jsdom/register from the setup, the render() call fails due to window not being defined. It seems it wants a global object called window, yet the jsdom instance has one (dom.window).
The reason for avoiding use of global window and document is that I want to be able to create separate instances to make sure that there is no shared data between instances (i.e. equivilent of two users making separate browser requests). I can't test for this if its using a global instance it seems.
I'm not using Jest for tests. It's still possible to use the getBy... queries if you avoid using the versions bound to screen, as the naked versions take the container element as the first argument, and this seems to work, but I'm concerned that the global and shared window element is going to make the tests brittle or just not work.
Looking at the source for RTL it seems that its just assuming window is a global and doesn't provide an alterantive, so wondering if anyone knows of a workaround or alternative.

Related

AnyLogic: Variables from Simulation will not be displayed anymore

I have added some variables in my simulation start page. Now I want to access them from the main class. However, with ((Simulation)getExperiment()).[...] the variables are no longer displayed. When I press option+space only one of about 150 variables is displayed. This one variable is not different from the other variables in the properties.
All variables are on public and I was able to access all of them a few weeks ago. Now not anymore, although I didn't change much in the model. I have already tried restarting. Did I accidentally remove some package or something? Can someone help me here please? I have only noticed the problem now as my model has runtime errors, presumably as the now unrecognized variables are not being initiated.
Pictures:
You should not access variables from experiments on Main. If you need access, you should pass them on as parameters into Main.
If you have hundreds of variables in the experiment, turn them into fields in a single Java class. Pass 1 instance of that Java class into Main as a parameter.
This way, you always have access, it is easy to add more variables, it is easy to change them and you do not need the awkward (and bad) type-casting you currently do

Is it possible to get the type of a variable while computing completion suggestions?

I'm thinking of creating a VSCode extension to help people use a library I am creating. I've looked in 50 places and can only see documentation on getting the plain text of the document in which the completion suggestions are triggered.
My library exposes a function with two parameters, both objects with the same keys, but the first one will be defined already and the 2nd one will be passed in as an object literal. For example
const obj1 = {a:1, b:2};
doLibraryThing(obj1, {a:[], b:[]});
I want to provide code completion, or a snippet, or anything that can detect that doLibraryThing is being called, and know what properties were defined in obj1, even though usually it will be imported from another file; and then use those properties to generate the suggestion with the same properties, {a:[], b:[]}.
Is this possible?

Cucumber's AfterConfiguration can't access helper modules

I have a modular Sinatra app without a DB and in order to test memcache, I have some test files that need to be created and deleted on the file system. I would like to generate these files in an AfterConfiguration hook using some helper methods (which are in a module shared with rspec, which also needs to create/delete these files for testing). I only want to create them once at the start of Cucumber.
I do not seem to be able to access the helpers from within AfterConfiguration, which lives in "support/hooks.rb." The helpers are accessible from Cucumber's steps, so I know they have been loaded properly.
This previous post seems to have an answer: Want to load seed data before running cucumber
The second example in this answer seems to say my modules should be accessible to my AfterConfiguration block, but I get "undefined method `foo' for nil:NilClass" when attempting to call helper method "foo".
I can pull everything out into a rakefile and run it that way, but I'd like to know what I'm missing here.
After digging around in the code, it appears that AfterConfiguration not only runs before any features are loaded, but before World is instantiated. Running self.class inside of the AfterConfig block returns NilClass. Running self.class inside of any other hook, such as a Before, will return MyWorldName. In retrospect, this makes sense as every feature is run in a separate instance of World.
This is why helpers defined as instance methods (ie def method_name) are unknown. Changing my methods to module methods (ie def ModuleName.method_name) allows them to function, since they really are module methods anyway.

Getting a new Shell instance from CompositionContainer in Prism 4 with MEF

I'm coming across some strange MEF behaviour in Prism, which I can't really explain. I've found a way around it that I'm not too happy with, so I'd really like to understand what's causing it.
I've declared my shell window class with a PartCreationPolicy of NonShared. And I'm trying to use the CompositionContainer.GetExportedValue<>() function from my MefBootstrapper to create a new instance of the Shell.
The strange thing is, if I call Container.GetExportedValue<>() before the shell has been created, I get a new object of type Shell, each time I call it. However, once the shell has been initialized, repeated calls to Container.GetExportedValue<>() return the same instance of the Shell.
It's as if the shell initialization somehow re-registers my Shell export as a Shared.
However, I don't see any calls in the bootstrapper code that explicitly try to achieve this.
Can anyone explain:
what action has this side effect
How (if possible) to restore the NonShared behaviour, so I can create multiple shells using MEF/ServiceLocator.
Cheers,
Mark
I'm not sure how Prism uses MEF, but here's a theory: How is the shell being created in normal startup? My guess is that it is not by calling GetExportedValue from the MEF container, but rather by calling the constructor for the Shell and then adding it to the container via ComposeParts() or using a CompositionBatch. A part added directly to the container in that way would override what was available in the catalog, and the CreationPolicy wouldn't apply either (because MEF isn't creating that part).
here is a answer for your multiple shell question. you have to check if the NonShared behavior is answered there.

How do I associate a CoffeeScript file with a view?

Just installed rails 3.1 rc1 and am trying to grok the best way to manage javascript with the new asset pipeline
By default all coffeescript is compiled into a single application.js file, this is a good thing.
Each seperate coffee script file is appended to the js file and wrapped in an anonymous function which is executed via the call method
A common scenario would be to use some jquery to turn various forms into ajax forms, update UI, etc...
Many of these scripts will be specific to a controller or action, I am trying to grok the 'conventional' way to handle this,
since everything is wrapped in an anonymous function how do I only execute just
the code for a particular controller / action, by default all of the anonymous functions are being executed
I did play around with some hacks where I load the controller and action name into js variables and then in
coffeescript check those to conditionally run code, I don't like that very much
my initial thought was that each coffee file would contain a js namespace/object and I would call the specific ones from the view,
going to spike this using the default_bare = true configuration
see How can I use option "--bare" in Rails 3.1 for CoffeeScript?
EDIT
Looking around some more: this looks like it might be the correct approach - "Can't find variable" error with Rails 3.1 and Coffeescript
There are two common approaches:
Make behavior conditional on the presence of a particular element. For instance, code to run a signup sheet should be prefaced with something like
if $('#signup').length > 0
Make behavior conditional on a class on the body element. You can set the body class using ERB. This is often desirable for stylesheets as well. The code would be something like
if $('body').hasClass 'user'
gistyle is a simple gem that helps you running action-specific javascript codes.
By following its setup, you set some data attributes in your body element, representing the current controller and action names. Then it will only call that action when the corresponding view is loaded.