diff --git a/types/ember-qunit/v3/ember-qunit-tests.ts b/types/ember-qunit/v3/ember-qunit-tests.ts index 5f8b9f4fd9..42768a42ca 100644 --- a/types/ember-qunit/v3/ember-qunit-tests.ts +++ b/types/ember-qunit/v3/ember-qunit-tests.ts @@ -8,6 +8,8 @@ import { moduleForModel, moduleForComponent, setResolver, + setupRenderingTest, + setupTest, } from 'ember-qunit'; moduleForComponent('x-foo', { @@ -113,3 +115,25 @@ test('It can calculate the result', function(assert) { skip('disabled test'); skip('disabled test', function(assert) { }); + +// https://github.com/emberjs/rfcs/blob/master/text/0232-simplify-qunit-testing-api.md#qunit-nested-modules-api +QUnit.module('some description', function(hooks) { + hooks.before(() => {}); + hooks.beforeEach(() => {}); + hooks.afterEach(() => {}); + hooks.after(() => {}); + + QUnit.test('it blends', function(assert) { + assert.ok(true, 'of course!'); + }); +}); + +// http://rwjblue.com/2017/10/23/ember-qunit-simplication/#setuprenderingtest +module('x-foo', function(hooks) { + setupRenderingTest(hooks); +}); + +// http://rwjblue.com/2017/10/23/ember-qunit-simplication/#setuprenderingtest +module('foo service', function(hooks) { + setupTest(hooks); +}); diff --git a/types/ember-qunit/v3/index.d.ts b/types/ember-qunit/v3/index.d.ts index 1eb74bc430..a42b5107af 100644 --- a/types/ember-qunit/v3/index.d.ts +++ b/types/ember-qunit/v3/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for ember-qunit 3.0 // Project: https://github.com/emberjs/ember-qunit#readme // Definitions by: Derek Wickern +// Frank Tan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -43,6 +44,42 @@ declare module 'ember-qunit' { */ export function setResolver(resolver: Ember.Resolver): void; + /** + * Sets up tests that need to render snippets of templates. + * + * The setupRenderingTest method is used for tests that need to render + * snippets of templates. It is also invoked in the callback scope of a + * QUnit module (aka "nested module"). + * + * Once invoked, all subsequent hooks.beforeEach and test invocations will + * have access to the following: + * * All of the methods / properties listed for `setupTest` + * * this.render(...) - Renders the provided template snippet returning a + * promise that resolves once rendering has completed + * * An importable render function that de-sugars into this.render will be + * the default output of blueprints + * * this.element - Returns the native DOM element representing the element + * that was rendered via this.render + * * this.$(...) - When jQuery is present, executes a jQuery selector with + * the current this.element as its root + */ + export function setupRenderingTest(hooks: NestedHooks): void; + + /** + * Sets up tests that do not need to render snippets of templates. + * + * The `setupTest` method is used for all types of tests except for those + * that need to render snippets of templates. It is invoked in the callback + * scope of a QUnit module (aka "nested module"). + * + * Once invoked, all subsequent hooks.beforeEach and test invocations will + * have access to the following: + * * this.owner - This exposes the standard "owner API" for the test environment. + * * this.set / this.setProperties - Allows setting values on the test context. + * * this.get / this.getProperties - Retrieves values from the test context. + */ + export function setupTest(hooks: NestedHooks): void; + export class QUnitAdapter extends Ember.Test.Adapter {} export { module, test, skip, only, todo } from 'qunit';