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

set attribute values for snapshotting input values #14

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions addon/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ function getDoctype() {
return doctype;
}

// Set the property value into the attribute value for snapshotting inputs
function setAttributeValues(dom) {
let inputs = dom.find('input');

for (let i = 0; i < inputs.length; i++) {
let input = inputs[i];
input.setAttribute('value', input.value);
}

return dom;
}

export function percySnapshot(name, options) {
// Skip if Testem is not available (we're probably running from `ember server` and Percy is not
// enabled anyway).
Expand All @@ -41,11 +53,13 @@ export function percySnapshot(name, options) {
let testingContainer = domCopy.find('#ember-testing-container');

if (scope) {
snapshotHtml = Ember.$('#ember-testing-container').find(scope).html();
snapshotHtml = Ember.$('#ember-testing-container').find(scope);
} else {
snapshotHtml = testingContainer.html();
snapshotHtml = testingContainer;
}

snapshotHtml = setAttributeValues(snapshotHtml).html();

// Hoist the testing container contents up to the body.
// We need to use the original DOM to keep the head stylesheet around.
domCopy.find('body').html(snapshotHtml);
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/components/dummy-box-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ test('name is autogenerated if given a Mocha test object', function(assert) {
};
percySnapshot(mochaTestDouble);
});

test('it snapshots input values', function(assert) {
this.render(hbs`{{input value="Testing"}}`);

assert.equal(this.$('input')[0].value, 'Testing', 'value property is set');
assert.equal(this.$('input').attr('value'), undefined, 'value attribute is not set');

percySnapshot('input with value');
});