import Ember from "ember";
import { moduleFor, test } from 'ember-qunit';

moduleFor('controller:gist', {
  needs: ['service:ember-cli'],

  beforeEach() {
    this._originalConfirm = window.confirm;
  },

  afterEach() {
    window.confirm = this._originalConfirm;
  }
});

test('deleting a gist requires confirmation', function(assert) {
  let controller = this.subject({
    transitionToRoute() {},
    notify: {
      info() {}
    }
  });
  let gistClass = Ember.Object.extend({
    called: false,
    destroyRecord() {
      this.set('called', true);
    }
  });

  window.confirm = () => true;
  let gist = gistClass.create();
  controller.send('deleteGist', gist);
  assert.ok(gist.get('called'), 'gist.destroyRecord was called when confirmed');

  window.confirm = () => false;
  gist = gistClass.create();
  controller.send('deleteGist', gist);
  assert.ok(!gist.get('called'), 'gist.destroyRecord was not called when not confirmed');
});

import Ember from "ember";
import { moduleFor, test } from 'ember-qunit';

moduleFor('controller:gist', {
  // Specify the other units that are required for this test.
  // needs: ['controller:foo']
  needs: ['service:ember-cli']
});

// Replace this with your real tests.
test('it exists', function(assert) {
  var controller = this.subject();
  assert.ok(controller);
});

test('deleting a gist requires confirmation', function(assert) {
  let cacheConfirm = window.confirm;
  let controller = this.subject({
    transitionToRoute() {},
    notify: {
      info() {}
    }
  });
  let gistClass = Ember.Object.extend({
    called: false,
    destroyRecord() {
      this.set('called', true);
    }
  });

  window.confirm = () => true;
  let gist = gistClass.create();
  controller.send('deleteGist', gist);
  assert.ok(gist.get('called'), 'gist.destroyRecord was called when confirmed');

  window.confirm = () => false;
  gist = gistClass.create();
  controller.send('deleteGist', gist);
  assert.ok(!gist.get('called'), 'gist.destroyRecord was not called when not confirmed');

  window.confirm = cacheConfirm;
});

--- 
+++ 
@@ -2,19 +2,18 @@
 import { moduleFor, test } from 'ember-qunit';
 
 moduleFor('controller:gist', {
-  // Specify the other units that are required for this test.
-  // needs: ['controller:foo']
-  needs: ['service:ember-cli']
-});
+  needs: ['service:ember-cli'],
 
-// Replace this with your real tests.
-test('it exists', function(assert) {
-  var controller = this.subject();
-  assert.ok(controller);
+  beforeEach() {
+    this._originalConfirm = window.confirm;
+  },
+
+  afterEach() {
+    window.confirm = this._originalConfirm;
+  }
 });
 
 test('deleting a gist requires confirmation', function(assert) {
-  let cacheConfirm = window.confirm;
   let controller = this.subject({
     transitionToRoute() {},
     notify: {
@@ -37,6 +36,4 @@
   gist = gistClass.create();
   controller.send('deleteGist', gist);
   assert.ok(!gist.get('called'), 'gist.destroyRecord was not called when not confirmed');
-
-  window.confirm = cacheConfirm;
 });
Address PR comments on unit test for confirm delete
