Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Mocha example in README calls fixture.restore() twice? #18

Open
klebba opened this issue Oct 22, 2016 · 3 comments
Open

Mocha example in README calls fixture.restore() twice? #18

klebba opened this issue Oct 22, 2016 · 3 comments

Comments

@klebba
Copy link

klebba commented Oct 22, 2016

This is the example in the README:

<script>
describe('<some-element>', function () {
  var someElement;

  beforeEach(function () {
    someElement = fixture('SomeElementFixture');
  });
});
</script>

This ends up calling restore() twice on the fixture, and seemingly creates the fixture again and again.

Would this not be preferable?:

<script>
describe('<some-element>', function () {
  var someElement = fixture('SomeElementFixture');;

  it('do some test', function () {
     // fixture is automatically restored in afterEach
  });
});
</script>
@nallown
Copy link

nallown commented Nov 12, 2016

I think that's the idea, that it recreates the fixture every time before a test runs so you'll have a fresh instance to work with.

@klebba
Copy link
Author

klebba commented Nov 14, 2016

Why bother to call restore on an instance you're about to ditch?

@nallown
Copy link

nallown commented Nov 16, 2016

If you do it beforeEach() then you'll generate a new fixture before each test, you know the it() tests.

So that way you'll have a new fresh element to work with before each test unlike in your second example where you have the same element to use throughout all of the it() tests in that describe() group.

Every test it() group should have a fresh element to work with which your second example wouldn't achieve, it would have the same one to use throughout all of the describe() group.

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

2 participants