Skip to content

Commit cb876e1

Browse files
committed
Resolve deprecations from tests
1 parent 3944c69 commit cb876e1

10 files changed

Lines changed: 53 additions & 60 deletions

test-app/tests/helpers/module-for-acceptance.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { resolve } from 'rsvp';
2+
import { setTesting } from '@ember/debug';
23
import { module } from 'qunit';
34
import startApp from '../helpers/start-app';
45
import destroyApp from '../helpers/destroy-app';
56
import { setResolverRegistry } from './resolver';
67
import QUnitTestAdapter from './qunit-test-adapter';
7-
import Ember from 'ember';
8+
import { setAdapter } from 'ember-testing/lib/setup_for_testing';
89

910
export default function (name, options = {}) {
1011
module(name, {
1112
beforeEach() {
12-
Ember.Test.adapter = QUnitTestAdapter.create();
13+
setAdapter(QUnitTestAdapter.create());
1314

1415
if (options.registry) {
1516
setResolverRegistry(options.registry);
@@ -20,7 +21,7 @@ export default function (name, options = {}) {
2021
);
2122
this.fixtureResetValue = testElementContainer.innerHTML;
2223

23-
Ember.testing = true;
24+
setTesting(true);
2425
this.application = startApp();
2526

2627
if (options.beforeEach) {
@@ -34,7 +35,7 @@ export default function (name, options = {}) {
3435
return resolve(afterEach)
3536
.then(() => destroyApp(this.application))
3637
.finally(() => {
37-
Ember.testing = false;
38+
setTesting(false);
3839

3940
document.getElementById('ember-testing-container').innerHTML =
4041
this.fixtureResetValue;

test-app/tests/helpers/qunit-module-for.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import Ember from 'ember';
1+
import { isTesting } from '@ember/debug';
22
import { module } from 'qunit';
33
import QUnitTestAdapter from './qunit-test-adapter';
4+
import { setAdapter } from 'ember-testing/lib/setup_for_testing';
45

56
export default function qunitModuleFor(testModule) {
67
module(testModule.name, {
78
beforeEach(assert) {
8-
if (Ember.testing) {
9+
if (isTesting()) {
910
throw new Error('should not have Ember.testing === true in beforeEach');
1011
}
11-
Ember.Test.adapter = QUnitTestAdapter.create();
12+
setAdapter(QUnitTestAdapter.create());
1213
testModule.setContext(this);
1314
return testModule.setup(assert).finally(() => {
14-
if (!Ember.testing) {
15+
if (!isTesting()) {
1516
throw new Error(
1617
'should have Ember.testing === true after tests have started'
1718
);
@@ -20,8 +21,8 @@ export default function qunitModuleFor(testModule) {
2021
},
2122
afterEach(assert) {
2223
return testModule.teardown(assert).finally(() => {
23-
Ember.Test.adapter = null;
24-
if (Ember.testing) {
24+
setAdapter(null);
25+
if (isTesting()) {
2526
throw new Error(
2627
'should not have Ember.testing === true after tests have finished'
2728
);

test-app/tests/helpers/qunit-test-adapter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Ember from 'ember';
21
import QUnit from 'qunit';
2+
import { Adapter } from '@ember/test';
33

44
/*
55
* This module is inlined here, because this library cannot depend on
@@ -30,7 +30,7 @@ function unhandledRejectionAssertion(current, error) {
3030
});
3131
}
3232

33-
export default Ember.Test.Adapter.extend({
33+
export default Adapter.extend({
3434
init() {
3535
this.doneCallbacks = [];
3636
},

test-app/tests/integration/setup-rendering-context-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import Ember from 'ember';
21
import { module, test } from 'qunit';
32
import Component, { setComponentTemplate } from '@ember/component';
43
import GlimmerComponent from '@glimmer/component';
54
import { helper } from '@ember/component/helper';
6-
import { registerWaiter } from '@ember/test';
5+
import { unregisterWaiter, registerWaiter } from '@ember/test';
76
import {
87
setupContext,
98
setupRenderingContext,
@@ -87,7 +86,7 @@ module('setupRenderingContext "real world"', function (hooks) {
8786
});
8887

8988
hooks.afterEach(async function () {
90-
Ember.Test.unregisterWaiter(this._waiter);
89+
unregisterWaiter(this._waiter);
9190
await teardownContext(this);
9291
});
9392

test-app/tests/test-helper.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as QUnit from 'qunit';
2-
import Ember from 'ember';
2+
3+
import { isTesting, setTesting } from '@ember/debug';
34
import { isSettled, getSettledState } from '@ember/test-helpers';
45
import { _backburner } from '@ember/runloop';
56
import './helpers/resolver';
@@ -49,13 +50,13 @@ QUnit.testDone(function ({ module, name }) {
4950
}
5051

5152
// this is used to ensure that no tests accidentally leak `Ember.testing` state
52-
if (Ember.testing) {
53-
let message = `Ember.testing should be reset after test has completed. ${module}: ${name} did not reset Ember.testing`;
53+
if (isTesting()) {
54+
let message = `isTesting() should be reset after test has completed. ${module}: ${name} did not reset isTesting()`;
5455
cleanupFailures.push(message);
5556

5657
// eslint-disable-next-line
5758
console.error(message);
58-
Ember.testing = false;
59+
setTesting(false);
5960
}
6061

6162
if (!isSettled()) {

test-app/tests/unit/settled-test.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Ember from 'ember';
1+
import { registerWaiter, unregisterWaiter } from '@ember/test';
22
import { module, test } from 'qunit';
33
import { isSettled, getSettledState } from '@ember/test-helpers';
44
import { macroCondition, dependencySatisfies } from '@embroider/macros';
@@ -69,20 +69,13 @@ module('settled', function (hooks) {
6969
return !this.isWaiterPending;
7070
};
7171

72-
// In Ember < 2.8 `registerWaiter` expected to be bound to
73-
// `Ember.Test` 😭
74-
//
75-
// Once we have dropped support for < 2.8 we should swap this to
76-
// use:
77-
//
78-
// import { registerWaiter } from '@ember/test';
79-
Ember.Test.registerWaiter(this._legacyWaiter);
72+
registerWaiter(this._legacyWaiter);
8073

8174
this._testWaiter = buildWaiter(WAITER_NAME);
8275
});
8376

8477
hooks.afterEach(function () {
85-
Ember.Test.unregisterWaiter(this._legacyWaiter);
78+
unregisterWaiter(this._legacyWaiter);
8679
resetWaiters();
8780
this.server.shutdown();
8881
_teardownAJAXHooks();

test-app/tests/unit/setup-context-test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { module, test } from 'qunit';
2+
import { isTesting } from '@ember/debug';
23
import Service, { inject as injectService } from '@ember/service';
34
import {
45
setupContext,
@@ -26,7 +27,6 @@ import {
2627
} from '../helpers/resolver';
2728
import App from '../../app';
2829
import config from '../../config/environment';
29-
import Ember from 'ember';
3030
import { deprecate, warn } from '@ember/debug';
3131

3232
module('setupContext', function (hooks) {
@@ -822,20 +822,17 @@ module('setupContext', function (hooks) {
822822
});
823823
});
824824

825-
test('Ember.testing', async function (assert) {
826-
assert.notOk(
827-
Ember.testing,
828-
'precond - Ember.testing is falsey before setup'
829-
);
825+
test('isTesting()', async function (assert) {
826+
assert.notOk(isTesting(), 'precond - isTesting() is falsey before setup');
830827

831828
context = {};
832829
let promise = setupContext(context);
833830

834-
assert.ok(Ember.testing, 'Ember.testing is truthy sync after setup');
831+
assert.ok(isTesting(), 'isTesting() is truthy sync after setup');
835832

836833
await promise;
837834

838-
assert.ok(Ember.testing, 'Ember.testing is truthy async after setup');
835+
assert.ok(isTesting(), 'isTesting() is truthy async after setup');
839836
});
840837
}
841838

test-app/tests/unit/setup-ember-onerror-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Ember from 'ember';
21
import { module, test } from 'qunit';
2+
import { getOnerror } from '@ember/-internals/error-handling';
33
import hasEmberVersion from '@ember/test-helpers/has-ember-version';
44
import { setupContext, teardownContext } from '@ember/test-helpers';
55
import { setupOnerror, resetOnerror } from '@ember/test-helpers';
@@ -23,38 +23,38 @@ module('setupOnerror', function (hooks) {
2323
await setupContext(context);
2424
});
2525

26-
test('Ember.onerror is undefined by default', function (assert) {
26+
test('onerror is undefined by default', function (assert) {
2727
assert.expect(1);
2828

29-
assert.equal(Ember.onerror, undefined);
29+
assert.equal(getOnerror(), undefined);
3030
});
3131

32-
test('Ember.onerror is setup correctly', async function (assert) {
32+
test('onerror is setup correctly', async function (assert) {
3333
assert.expect(2);
3434

3535
let onerror = (err) => err;
3636

37-
assert.equal(Ember.onerror, undefined);
37+
assert.equal(getOnerror(), undefined);
3838

3939
setupOnerror(onerror);
4040

41-
assert.equal(Ember.onerror, onerror);
41+
assert.equal(getOnerror(), onerror);
4242
});
4343

44-
test('Ember.onerror is reset correctly', async function (assert) {
44+
test('onerror is reset correctly', async function (assert) {
4545
assert.expect(3);
4646

4747
let onerror = (err) => err;
4848

49-
assert.equal(Ember.onerror, undefined);
49+
assert.equal(getOnerror(), undefined);
5050

5151
setupOnerror(onerror);
5252

53-
assert.equal(Ember.onerror, onerror);
53+
assert.equal(getOnerror(), onerror);
5454

5555
resetOnerror();
5656

57-
assert.equal(Ember.onerror, undefined);
57+
assert.equal(getOnerror(), undefined);
5858
});
5959
});
6060

test-app/tests/unit/teardown-context-test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
} from '@ember/test-helpers';
1111
import { setResolverRegistry } from '../helpers/resolver';
1212
import hasEmberVersion from '@ember/test-helpers/has-ember-version';
13-
import Ember from 'ember';
13+
import { isTesting } from '@ember/debug';
14+
1415
import hasjQuery from '../helpers/has-jquery';
1516
import ajax from '../helpers/ajax';
1617
import Pretender from 'pretender';
@@ -48,12 +49,12 @@ module('teardownContext', function (hooks) {
4849
assert.ok(instance.isDestroying, 'destroying');
4950
});
5051

51-
test('it sets Ember.testing to false', async function (assert) {
52-
assert.ok(Ember.testing, 'precond - Ember.testing is truthy');
52+
test('it sets isTesting() to false', async function (assert) {
53+
assert.ok(isTesting(), 'precond - isTesting() is truthy');
5354

5455
await teardownContext(context);
5556

56-
assert.notOk(Ember.testing, 'Ember.testing is falsey after teardown');
57+
assert.notOk(isTesting(), 'isTesting() is falsey after teardown');
5758
});
5859

5960
test('it unsets the context', async function (assert) {

test-app/tests/unit/validate-error-handler-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { getOnerror, setOnerror } from '@ember/-internals/error-handling';
12
import { module, test } from 'qunit';
2-
import Ember from 'ember';
33

44
import { validateErrorHandler } from '@ember/test-helpers';
55

@@ -52,41 +52,41 @@ module('validateErrorHandler', function (hooks) {
5252

5353
module('without a passed in callback', function (hooks) {
5454
hooks.beforeEach(function () {
55-
this.originalOnerror = Ember.onerror;
55+
this.originalOnerror = getOnerror();
5656
});
5757

5858
hooks.afterEach(function () {
59-
Ember.onerror = this.originalOnerror;
59+
setOnerror(this.originalOnerror);
6060
});
6161

6262
test('invokes the provided callback', function (assert) {
6363
assert.expect(1);
6464

65-
Ember.onerror = function () {
65+
setOnerror(function () {
6666
assert.ok(true, 'error handler was invoked');
67-
};
67+
});
6868

6969
validateErrorHandler();
7070
});
7171

7272
test('considers handler missing to be a valid handler', function (assert) {
73-
Ember.onerror = undefined;
73+
setOnerror(undefined);
7474
let result = validateErrorHandler();
7575

7676
assert.valid(result);
7777
});
7878

7979
test('when the provided function does _not_ rethrow it is invalid', function (assert) {
80-
Ember.onerror = function () {};
80+
setOnerror(function () {});
8181
let result = validateErrorHandler();
8282

8383
assert.invalid(result);
8484
});
8585

8686
test('when the provided function does rethrow it is valid', function (assert) {
87-
Ember.onerror = function (error) {
87+
setOnerror(function (error) {
8888
throw error;
89-
};
89+
});
9090

9191
let result = validateErrorHandler();
9292

0 commit comments

Comments
 (0)