import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import {
  a11yAuditIf,
  setEnableA11yAudit,
} from 'ember-a11y-testing/test-support';

module('Integration | Helper | a11yAuditIf', function (hooks) {
  setupRenderingTest(hooks);

  test('a11yAuditIf should not execute a11yAudit', async function (assert) {
    await render(hbs`{{#axe-component}}<button></button>{{/axe-component}}`);

    await a11yAuditIf(this.element);

    assert.ok(true, 'a11yAuditIf should not run a11yAudit');
  });

  test('a11yAudit should execute a11yAudit if enableA11yAudit=true is passed as query param', async function (assert) {
    try {
      await render(hbs`{{#axe-component}}<button></button>{{/axe-component}}`);

      setEnableA11yAudit(true);

      try {
        await a11yAuditIf(this.element);
        assert.ok(false, 'audit should have failed');
      } catch (error) {
        let foundExpectedError = error.message.startsWith(
          'The page should have no accessibility violations.'
        );
        assert.ok(foundExpectedError);
      }
    } finally {
      setEnableA11yAudit(false);
    }
  });
});

@@ -864,29 +864,45 @@
 ue);%0A%0A      
-try %7B
+await assert.rejects(
 %0A        awa
@@ -894,30 +894,24 @@
 ts(%0A        
-await 
 a11yAuditIf(
@@ -927,266 +927,126 @@
 ent)
-;%0A        assert.ok(false, 'audit should have failed');%0A      %7D catch (error) %7B%0A        let foundExpectedError = error.message.startsWith(%0A          'The page should have no accessibility violations.'%0A        );%0A        assert.ok(foundExpectedError);
+,%0A        /The page should have no accessibility violations. Violations:/,%0A        'error message is correct'
 %0A      
-%7D
+);
 %0A   

Convert to assert.rejects