From f21d70fbd948b9bad0dd168a25ba2e814c4eaba2 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Mon, 26 Jan 2015 14:16:59 -0500 Subject: [PATCH] [FEATURE] ember-testing-checkbox-helpers fixes #9798 (https://github.com/emberjs/ember.js/pull/9798#issuecomment-69384792) When test driving, `click` and `unclick` are useful for ensuring the state of a form. ```javascript export default DS.Model.extend({ title: DS.attr(), body: DS.attr(), isDraft: DS.attr("boolean", defaultValue: false) }); test("doesn't publish posts in draft mode", function() { fillIn("#title", "this post is hidden"); fillIn("#body", "this won't be displayed"); check("#is-draft"); click("#submit"); andThen(function() { equal(find(".post:contains('this post is hidden')").length, 0); }); }); ``` `check` and `uncheck` allow the test to remain unchanged if the `defaultValue` of `isDraft` changes from `false` to `true`. The test only cares that: * when `click("#submit")` executes, the `#is-draft` checkbox is `checked` * `isDraft` is true --- packages/ember-testing/lib/helpers.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/ember-testing/lib/helpers.js b/packages/ember-testing/lib/helpers.js index a4808d2bc54..f81b36e786b 100644 --- a/packages/ember-testing/lib/helpers.js +++ b/packages/ember-testing/lib/helpers.js @@ -89,9 +89,9 @@ function check(app, selector, context) { Ember.assert('To check \'' + selector + '\', the input must be a checkbox', type === 'checkbox'); - run(function() { - $el.prop('checked', true).change(); - }); + if (!$el.prop('checked')) { + app.testHelpers.click(selector, context); + } return app.testHelpers.wait(); } @@ -103,9 +103,9 @@ function uncheck(app, selector, context) { Ember.assert('To uncheck \'' + selector + '\', the input must be a checkbox', type === 'checkbox'); - run(function() { - $el.prop('checked', false).change(); - }); + if ($el.prop('checked')) { + app.testHelpers.click(selector, context); + } return app.testHelpers.wait(); }