jasmine-jquery icon indicating copy to clipboard operation
jasmine-jquery copied to clipboard

ability to disable fixture cleanUp between specs

Open jywarren opened this issue 9 years ago • 3 comments

I've added a way to disable fixture teardown by disabling the cleanUp method; a bit messy, but for when fixture generation is expensive, or the environment is complex enough that I want to test a series of things in a persistent environment.

I know not everyone wants this -- there's a lot to be said for small, self-contained specs and contexts, but is there any interest in building such a feature into jasmine-ajax?

  var cleanUp;

  // disable cleanUp() method to persist the fixture across specs
  persistFixture = function() {

    cleanUp = jasmine.getFixtures().cleanUp; // save the cleanUp function

    jasmine.getFixtures().cleanUp = function() {}; // replace it with a fake one

  }

  // restore non-persistent fixture behavior
  unPersistFixture = function() {

    jasmine.getFixtures().cleanUp = cleanUp;

  }

Er, obviously it'd be easier to do in the library itself with a switch instead of the jiggery-pokery above, i just thought I'd share how I did it for clarity.

jywarren avatar Nov 06 '15 15:11 jywarren

For what it is worth, after many hours of troubleshooting a missing jasmine-fixtures element, I stumbled onto the same solution. I have a series of tests which require an initial HTML element to be loaded and subsequent tests interact with the HTML output. I was getting erratic behavior until I realized it was because the jasmine.getFixtures().cleanUp was being called after each it() and describe() call.

It would seem to me the sensible solution is to scope the fixture to the level it was defined. If I create it at the top of my hierarchy of describe & it statements, it persists until that block is completed. That way, if someone wants to load a fixture within a it() statement, it will be cleaned up then. If someone wants to load a fixture in a beforeAll before running all their specs, it will last for that duration.

In the meantime, I will have to use a solution like above to unwire the default behavior.

This appears to be the same issue causing #275 as well.

chrisnelson avatar May 03 '16 20:05 chrisnelson

I always disable the fixture cleanup by overwriting the cleanup method to an empty method, to debug a failed test inside chrome and it helps a lot to reproduce the fail in the actual application just for reproduction. A kind of easier feature to disable the cleanup would be nice. This is actually a pretty hidden undocumented workaround but it really helps a lot.

GerroDen avatar Jun 29 '16 11:06 GerroDen

Ended up doing a similar thing to decrease test run-time where the overhead of adding and removing elements repeatedly was getting really high.

Our change intercepts clean-up in beforeAll and runs the intercepted clean-up in afterAll before restoring the clean-up functions. A public API exposed to do this would be nice.

rajsite avatar Jul 19 '16 22:07 rajsite