Skip to content

Commit

Permalink
Update ember-testing tests to new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Dec 22, 2017
1 parent 2069333 commit d7be5d5
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 286 deletions.
29 changes: 17 additions & 12 deletions packages/ember-testing/tests/adapters/adapter_test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import { run } from 'ember-metal';
import Adapter from '../../adapters/adapter';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

var adapter;

QUnit.module('ember-testing Adapter', {
setup() {
moduleFor('ember-testing Adapter', class extends AbstractTestCase {
constructor() {
super();
adapter = new Adapter();
},
}

teardown() {
run(adapter, adapter.destroy);
}
});

QUnit.test('exception throws', function() {
var error = 'Hai';
var thrown;
['@test exception throws'](assert) {
var error = 'Hai';
var thrown;

try {
adapter.exception(error);
} catch (e) {
thrown = e;
try {
adapter.exception(error);
} catch (e) {
thrown = e;
}
assert.equal(thrown, error);
}
equal(thrown, error);

});

74 changes: 39 additions & 35 deletions packages/ember-testing/tests/adapters/qunit_test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
import { run } from 'ember-metal';
import QUnitAdapter from '../../adapters/qunit';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

var adapter;

QUnit.module('ember-testing QUnitAdapter', {
setup() {
moduleFor('ember-testing QUnitAdapter', class extends AbstractTestCase {
constructor() {
super();
adapter = new QUnitAdapter();
},
}

teardown() {
run(adapter, adapter.destroy);
}
});

QUnit.test('asyncStart calls stop', function() {
var originalStop = QUnit.stop;
try {
QUnit.stop = function() {
ok(true, 'stop called');
};
adapter.asyncStart();
} finally {
QUnit.stop = originalStop;
['@test asyncStart calls stop'](assert) {
var originalStop = QUnit.stop;
try {
QUnit.stop = function() {
assert.ok(true, 'stop called');
};
adapter.asyncStart();
} finally {
QUnit.stop = originalStop;
}
}
});

QUnit.test('asyncEnd calls start', function() {
var originalStart = QUnit.start;
try {
QUnit.start = function() {
ok(true, 'start called');
};
adapter.asyncEnd();
} finally {
QUnit.start = originalStart;
['@test asyncEnd calls start'](assert) {
var originalStart = QUnit.start;
try {
QUnit.start = function() {
assert.ok(true, 'start called');
};
adapter.asyncEnd();
} finally {
QUnit.start = originalStart;
}
}
});

QUnit.test('exception causes a failing assertion', function() {
var error = { err: 'hai' };
var originalOk = window.ok;
try {
window.ok = function(val, msg) {
originalOk(!val, 'ok is called with false');
originalOk(msg, '{err: "hai"}');
};
adapter.exception(error);
} finally {
window.ok = originalOk;
['@test exception causes a failing assertion']() {
var error = { err: 'hai' };
var originalOk = window.ok;
try {
window.ok = function(val, msg) {
originalOk(!val, 'ok is called with false');
originalOk(msg, '{err: "hai"}');
};
adapter.exception(error);
} finally {
window.ok = originalOk;
}
}
});

109 changes: 56 additions & 53 deletions packages/ember-testing/tests/adapters_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import Test from '../test';
import Adapter from '../adapters/adapter';
import QUnitAdapter from '../adapters/qunit';
import { Application as EmberApplication } from 'ember-application';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

var App, originalAdapter, originalQUnit, originalWindowOnerror;

QUnit.module('ember-testing Adapters', {
setup() {
moduleFor('ember-testing Adapters', class extends AbstractTestCase {
constructor() {
super();
originalAdapter = Test.adapter;
originalQUnit = window.QUnit;
originalWindowOnerror = window.onerror;
},
}

teardown() {
if (App) {
run(App, App.destroy);
Expand All @@ -23,72 +26,72 @@ QUnit.module('ember-testing Adapters', {
window.QUnit = originalQUnit;
window.onerror = originalWindowOnerror;
}
});

QUnit.test('Setting a test adapter manually', function() {
expect(1);
var CustomAdapter;
['@test Setting a test adapter manually'](assert) {
assert.expect(1);
var CustomAdapter;

CustomAdapter = Adapter.extend({
asyncStart() {
ok(true, 'Correct adapter was used');
}
});
CustomAdapter = Adapter.extend({
asyncStart() {
assert.ok(true, 'Correct adapter was used');
}
});

run(function() {
App = EmberApplication.create();
Test.adapter = CustomAdapter.create();
App.setupForTesting();
});
run(function () {
App = EmberApplication.create();
Test.adapter = CustomAdapter.create();
App.setupForTesting();
});

Test.adapter.asyncStart();
});
Test.adapter.asyncStart();
}

QUnit.test('QUnitAdapter is used by default (if QUnit is available)', function() {
expect(1);
['@test QUnitAdapter is used by default (if QUnit is available)'](assert) {
assert.expect(1);

Test.adapter = null;
Test.adapter = null;

run(function() {
App = EmberApplication.create();
App.setupForTesting();
});
run(function () {
App = EmberApplication.create();
App.setupForTesting();
});

ok(Test.adapter instanceof QUnitAdapter);
});
assert.ok(Test.adapter instanceof QUnitAdapter);
}

QUnit.test('Adapter is used by default (if QUnit is not available)', function() {
expect(2);
['@test Adapter is used by default (if QUnit is not available)'](assert) {
assert.expect(2);

delete window.QUnit;
delete window.QUnit;

Test.adapter = null;
Test.adapter = null;

run(function() {
App = EmberApplication.create();
App.setupForTesting();
});
run(function () {
App = EmberApplication.create();
App.setupForTesting();
});

ok(Test.adapter instanceof Adapter);
ok(!(Test.adapter instanceof QUnitAdapter));
});
assert.ok(Test.adapter instanceof Adapter);
assert.ok(!(Test.adapter instanceof QUnitAdapter));
}

['@test With Ember.Test.adapter set, errors in synchronous Ember.run are bubbled out'](assert) {
let thrown = new Error('Boom!');

QUnit.test('With Ember.Test.adapter set, errors in synchronous Ember.run are bubbled out', function (assert) {
let thrown = new Error('Boom!');
let caughtInAdapter, caughtInCatch;
Test.adapter = QUnitAdapter.create({
exception(error) {
caughtInAdapter = error;
}
});

let caughtInAdapter, caughtInCatch;
Test.adapter = QUnitAdapter.create({
exception(error) {
caughtInAdapter = error;
try {
run(() => { throw thrown; });
} catch (e) {
caughtInCatch = e;
}
});

try {
run(() => { throw thrown; });
} catch(e) {
caughtInCatch = e;
assert.equal(caughtInAdapter, undefined, 'test adapter should never receive synchronous errors');
assert.equal(caughtInCatch, thrown, 'a "normal" try/catch should catch errors in sync run');
}

assert.equal(caughtInAdapter, undefined, 'test adapter should never receive synchronous errors');
assert.equal(caughtInCatch, thrown, 'a "normal" try/catch should catch errors in sync run');
});
Loading

0 comments on commit d7be5d5

Please sign in to comment.