Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to disable HTML fixture resets #205

Closed
rbakr opened this issue May 20, 2013 · 1 comment
Closed

Allow users to disable HTML fixture resets #205

rbakr opened this issue May 20, 2013 · 1 comment

Comments

@rbakr
Copy link
Contributor

rbakr commented May 20, 2013

In version 1.0.10, we introduced a new behavior for the @venus-fixture annotation. Now, before each test runs, we reset the fixture DOM elements to their initial state.

Consider this example:

mycontrol.fixture.html

<ul id="my-list">
  <li>List Item 1</li>
</ul>

mycontrol.spec.js

/**
 * @venus-library mocha
 * @venus-fixture mycontrol.fixture.html
 */
describe('my control', function () {
  var ul = document.querySelector('#my-list');

  it('should add one list item', function () {
    var li = document.createElement('li');
    li.innerText = 'New List Item';
    ul.appendChild(li);
    expect(ul.childElementCount).to.be(1);
  });

  it('should set classname on ul', function () {
    ul.className = 'foo';
    expect(ul.className).to.be('foo');
  });
});

The should set classname on ul test will fail. This is because the innerHTML of the DOM element containing the HTML fixture code is wiped out between each test.

To fix this problem, the user would need to re-select the <ul id="my-list"> element from the DOM before each test runs. The easiest way to do this, in this mocha based example, is to use a beforeEach() hook:

mycontrol.spec.js with before each hook

/**
 * @venus-library mocha
 * @venus-fixture mycontrol.fixture.html
 */
describe('my control', function () {
  var ul;

  beforeEach(function () {
    ul = document.querySelector('#my-list');
  });

  it('should add one list item', function () {
    var li = document.createElement('li');
    li.innerText = 'New List Item';
    ul.appendChild(li);
    expect(ul.childElementCount).to.be(1);
  });

  it('should set classname on ul', function () {
    ul.className = 'foo';
    expect(ul.className).to.be('foo');
  });
});

We are introducing a new annotation, @venus-fixture-reset false, to disable this functionality.

@sethmcl
Copy link
Contributor

sethmcl commented Jul 8, 2013

Fixed by #230

@sethmcl sethmcl closed this as completed Jul 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants