ember-test-helpers: Update types to v0.7

This commit is contained in:
Frank Tan
2017-12-28 10:05:57 -05:00
parent d76f2715f9
commit 5913e4fcb1
3 changed files with 38 additions and 4 deletions

View File

@@ -133,7 +133,7 @@ module('x-foo', function(hooks) {
setupRenderingTest(hooks);
});
// http://rwjblue.com/2017/10/23/ember-qunit-simplication/#setuprenderingtest
// http://rwjblue.com/2017/10/23/ember-qunit-simplication/#setuptest
module('foo service', function(hooks) {
setupTest(hooks);
});

View File

@@ -1,8 +1,10 @@
/// <reference types="qunit" />
import { ModuleCallbacks, TestModule } from "ember-test-helpers";
import { ModuleCallbacks, TestContext, TestModule } from "ember-test-helpers";
import wait from 'ember-test-helpers/wait';
import hasEmberVersion from 'ember-test-helpers/has-ember-version';
import hbs from 'htmlbars-inline-precompile';
function moduleFor(name: string, description: string, callbacks: ModuleCallbacks) {
const module = new TestModule(name, description, callbacks);
@@ -23,3 +25,29 @@ async function testWait() {
if (hasEmberVersion(2, 10)) {
// ...
}
// https://github.com/emberjs/ember-test-helpers/blob/f07e86914f2a3823c4cb6787307f9ba2bf447e68/tests/unit/setup-context-test.js
QUnit.test('it sets up this.owner', function(this: TestContext, assert: Assert) {
const { owner } = this;
assert.ok(owner, 'owner was setup');
assert.equal(typeof owner.lookup, 'function', 'has expected lookup interface');
if (hasEmberVersion(2, 12)) {
assert.equal(typeof owner.factoryFor, 'function', 'has expected factory interface');
}
});
QUnit.test('can pauseTest to be resumed "later"', async function(this: TestContext, assert: Assert) {
const promise = this.pauseTest();
this.resumeTest();
await promise;
});
// https://github.com/emberjs/ember-test-helpers/blob/fb4c8d4cd36b54728ce180227f865b1fa0162632/tests/unit/setup-rendering-context-test.js
QUnit.test('render exposes an `.element` property', async function(this: TestContext, assert: Assert) {
await this.render(hbs`<p>Hello!</p>`);
assert.equal(this.element.textContent, 'Hello!');
});

View File

@@ -1,4 +1,4 @@
// Type definitions for ember-test-helpers 0.6
// Type definitions for ember-test-helpers 0.7
// Project: https://github.com/emberjs/ember-test-helpers#readme
// Definitions by: Derek Wickern <https://github.com/dwickern>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -34,7 +34,7 @@ declare module 'ember-test-helpers' {
send(actionName: string): void;
$: JQueryStatic;
subject(options?: {}): any;
render(template?: string | string[] | TemplateFactory): void;
render(template?: string | string[] | TemplateFactory): Promise<void>;
clearRender(): void;
registry: Ember.Registry;
container: Ember.Container;
@@ -47,6 +47,12 @@ declare module 'ember-test-helpers' {
controller(name: string, options?: { as: string }): any;
service(name: string, options?: { as: string }): any;
};
owner: Ember.ApplicationInstance & {
factoryFor(fullName: string, options?: {}): any;
};
pauseTest(): Promise<void>;
resumeTest(): void;
element: Element;
}
class TestModule {