Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

ability to disable fixture cleanUp between specs #270

Open
jywarren opened this issue Nov 6, 2015 · 3 comments
Open

ability to disable fixture cleanUp between specs #270

jywarren opened this issue Nov 6, 2015 · 3 comments

Comments

@jywarren
Copy link

jywarren commented Nov 6, 2015

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.

@chrisnelson
Copy link

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.

@GerroDen
Copy link

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.

@rajsite
Copy link

rajsite commented Jul 19, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants