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

Update ember-testing tests to new syntax #16022

Merged
merged 3 commits into from
Dec 30, 2017
Merged
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
2 changes: 1 addition & 1 deletion packages/ember-testing/lib/adapters/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export default Adapter.extend({
QUnit.start();
},
exception(error) {
ok(false, inspect(error));
QUnit.config.current.assert.ok(false, inspect(error));
}
});
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);

});

76 changes: 41 additions & 35 deletions packages/ember-testing/tests/adapters/qunit_test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very sure what to do about QUnit.stop and QUnit.start

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The places that are explicitly testing asyncStart and asyncStop should continue to use QUnit.stop / QUnit.start for now, but anywhere else it is being done should be migrated to assert.async().

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again

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'](assert) {
var error = { err: 'hai' };
let originalPushResult = assert.pushResult;
try {
assert.pushResult = function (resultInfo) {
// Inverts the result so we can test failing assertions
resultInfo.result = !resultInfo.result;
resultInfo.message = `Failed: ${resultInfo.message}`;
originalPushResult(resultInfo);
};
adapter.exception(error);
} finally {
assert.pushResult = originalPushResult;
}
}
});

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