From 0d292c722747b00b919bf9e31a1ad2e9ebd91cbc Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Mon, 16 Oct 2017 14:35:51 -0400 Subject: [PATCH] Move `setContext` into `setupContext`. --- addon-test-support/index.js | 3 +-- .../legacy-0-6-x/abstract-test-module.js | 2 +- addon-test-support/legacy-0-6-x/test-context.js | 13 ------------- .../legacy-0-6-x/test-module-for-acceptance.js | 2 +- addon-test-support/setup-context.js | 17 +++++++++++++++++ tests/unit/setup-context-test.js | 6 +++++- 6 files changed, 25 insertions(+), 18 deletions(-) delete mode 100644 addon-test-support/legacy-0-6-x/test-context.js diff --git a/addon-test-support/index.js b/addon-test-support/index.js index 60ab0f007..d69e8def9 100644 --- a/addon-test-support/index.js +++ b/addon-test-support/index.js @@ -3,10 +3,9 @@ export { default as TestModule } from './legacy-0-6-x/test-module'; export { default as TestModuleForAcceptance } from './legacy-0-6-x/test-module-for-acceptance'; export { default as TestModuleForComponent } from './legacy-0-6-x/test-module-for-component'; export { default as TestModuleForModel } from './legacy-0-6-x/test-module-for-model'; -export { getContext, setContext, unsetContext } from './legacy-0-6-x/test-context'; export { setResolver } from './resolver'; -export { default as setupContext } from './setup-context'; +export { default as setupContext, getContext, setContext, unsetContext } from './setup-context'; export { default as teardownContext } from './teardown-context'; export { default as setupRenderingContext } from './setup-rendering-context'; export { default as teardownRenderingContext } from './teardown-rendering-context'; diff --git a/addon-test-support/legacy-0-6-x/abstract-test-module.js b/addon-test-support/legacy-0-6-x/abstract-test-module.js index 602aeac70..c9f060888 100644 --- a/addon-test-support/legacy-0-6-x/abstract-test-module.js +++ b/addon-test-support/legacy-0-6-x/abstract-test-module.js @@ -3,7 +3,7 @@ import { Promise as EmberPromise, resolve } from 'rsvp'; import { assign, merge as emberMerge } from '@ember/polyfills'; import { _setupPromiseListeners, _teardownPromiseListeners } from '../ext/rsvp'; import { _setupAJAXHooks, _teardownAJAXHooks } from '../wait'; -import { getContext, setContext, unsetContext } from './test-context'; +import { getContext, setContext, unsetContext } from '../setup-context'; import Ember from 'ember'; diff --git a/addon-test-support/legacy-0-6-x/test-context.js b/addon-test-support/legacy-0-6-x/test-context.js deleted file mode 100644 index f7b6a549b..000000000 --- a/addon-test-support/legacy-0-6-x/test-context.js +++ /dev/null @@ -1,13 +0,0 @@ -var __test_context__; - -export function setContext(context) { - __test_context__ = context; -} - -export function getContext() { - return __test_context__; -} - -export function unsetContext() { - __test_context__ = undefined; -} diff --git a/addon-test-support/legacy-0-6-x/test-module-for-acceptance.js b/addon-test-support/legacy-0-6-x/test-module-for-acceptance.js index ce78ec204..0fee40de3 100644 --- a/addon-test-support/legacy-0-6-x/test-module-for-acceptance.js +++ b/addon-test-support/legacy-0-6-x/test-module-for-acceptance.js @@ -1,6 +1,6 @@ import { run } from '@ember/runloop'; import AbstractTestModule from './abstract-test-module'; -import { getContext } from './test-context'; +import { getContext } from '../setup-context'; export default class extends AbstractTestModule { setupContext() { diff --git a/addon-test-support/setup-context.js b/addon-test-support/setup-context.js index 612c92cf2..7a28f9fa6 100644 --- a/addon-test-support/setup-context.js +++ b/addon-test-support/setup-context.js @@ -4,15 +4,32 @@ import buildOwner from './build-owner'; import { _setupPromiseListeners } from './ext/rsvp'; import { _setupAJAXHooks } from './wait'; +let __test_context__; + +export function setContext(context) { + __test_context__ = context; +} + +export function getContext() { + return __test_context__; +} + +export function unsetContext() { + __test_context__ = undefined; +} + /* * Responsible for: * + * - sets the "global testing context" to the provided context * - create an owner object and set it on the provided context (e.g. this.owner) * - setup this.set, this.setProperties, this.get, and this.getProperties to the provided context * - setting up AJAX listeners * - setting up RSVP promise integration */ export default function(context, options = {}) { + setContext(context); + let resolver = options.resolver; let owner = buildOwner(resolver); diff --git a/tests/unit/setup-context-test.js b/tests/unit/setup-context-test.js index 7e67f9e81..34d8c4a35 100644 --- a/tests/unit/setup-context-test.js +++ b/tests/unit/setup-context-test.js @@ -1,6 +1,6 @@ import { module, test } from 'qunit'; import Service from '@ember/service'; -import { setupContext } from 'ember-test-helpers'; +import { setupContext, getContext } from 'ember-test-helpers'; import hasEmberVersion from 'ember-test-helpers/has-ember-version'; import { setResolverRegistry, createCustomResolver } from '../helpers/resolver'; @@ -75,6 +75,10 @@ module('setupContext', function(hooks) { 'getProperties reads content from context' ); }); + + test('it calls setContext with the provided context', function(assert) { + assert.equal(getContext(), context); + }); }); module('with custom options', function() {