Skip to content

Commit

Permalink
Merge pull request #1180 from vstefanovic97/main
Browse files Browse the repository at this point in the history
Fix @typs/qunit overrides for latest qunit version
  • Loading branch information
NullVoxPopuli authored Oct 31, 2024
2 parents 0fd92b5 + 9e9a27b commit 11cfab8
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 38 deletions.
2 changes: 1 addition & 1 deletion addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@release-it-plugins/lerna-changelog": "^6.0.0",
"@rollup/plugin-babel": "^5.3.0",
"@tsconfig/ember": "^2.0.0",
"@types/qunit": "^2.19.6",
"@types/qunit": "^2.19.12",
"@types/rsvp": "^4.0.4",
"concurrently": "^8.0.1",
"ember-source": "^5.0.0",
Expand Down
66 changes: 42 additions & 24 deletions addon/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,6 @@ declare global {
}

interface QUnit {
/**
* Add a test to run.
*
* Add a test to run using `QUnit.test()`.
*
* The `assert` argument to the callback contains all of QUnit's assertion
* methods. Use this argument to call your test assertions.
*
* `QUnit.test()` can automatically handle the asynchronous resolution of a
* Promise on your behalf if you return a thenable Promise as the result of
* your callback function.
*
* @param name Title of unit being tested
* @param callback Function to close over assertions
*/
// SAFETY: this is just wildly, impossibly unsafe. QUnit cannot -- ever! --
// provide this guarantee. However, it's also the only way to support TS
// in tests in Ember until we move the community over entirely to using
// `<template>` and local scope.
test<TC extends TestContext>(
name: string,
callback: (this: TC, assert: Assert) => void | Promise<unknown>
): void;

/**
* Adds a test to exclusively run, preventing all other tests from running.
*
Expand Down Expand Up @@ -269,4 +245,46 @@ declare global {
callback?: (this: TC, assert: Assert) => void | Promise<unknown>
): void;
}

namespace QUnit {
interface TestFunction {
// SAFETY: this is just wildly, impossibly unsafe. QUnit cannot -- ever! --
// provide this guarantee. However, it's also the only way to support TS
// in tests in Ember until we move the community over entirely to using
// `<template>` and local scope.
<TC extends TestContext>(
name: string,
callback: (this: TC, assert: Assert) => void | Promise<unknown>
): void;
}

interface SkipFunction {
<TC extends TestContext>(
name: string,
callback?: (this: TC, assert: Assert) => void | Promise<unknown>
): void;
}

interface TodoFunction {
<TC extends TestContext>(
name: string,
callback?: (this: TC, assert: Assert) => void | Promise<unknown>
): void;
}

interface OnlyFunction {
<TC extends TestContext>(
name: string,
callback: (this: TC, assert: Assert) => void | Promise<unknown>
): void;
}

interface EachFunction {
<TC extends TestContext, T>(
name: string,
dataset: T[],
callback: (this: TC, assert: Assert, data: T) => void | Promise<unknown>
): void;
}
}
}
21 changes: 11 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@tsconfig/ember": "^2.0.0",
"@types/qunit": "^2.19.6",
"@types/qunit": "^2.19.12",
"@types/rsvp": "^4.0.4",
"concurrently": "^8.0.1",
"ember-angle-bracket-invocation-polyfill": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion test-buildtime-options-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@tsconfig/ember": "^2.0.0",
"@types/qunit": "^2.19.6",
"@types/qunit": "^2.19.12",
"@types/rsvp": "^4.0.4",
"concurrently": "^8.0.1",
"ember-angle-bracket-invocation-polyfill": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion test-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@ember/test-helpers": "^3.0.3",
"@glimmer/component": "^1.1.2",
"@tsconfig/ember": "^2.0.0",
"@types/qunit": "^2.19.6",
"@types/qunit": "^2.19.12",
"ember-cli-htmlbars": "^6.3.0",
"ember-resolver": "^10.1.0",
"ember-source": "^5.0.0",
Expand Down
42 changes: 42 additions & 0 deletions test-types/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,45 @@ module('with setup options', function (hooks) {
setupRenderingTest(hooks, { resolver });
setupApplicationTest(hooks, { resolver });
});

module('methods on test function', function () {
test.each('example with each', [1,2,3], async function (assert, number) {
// setup the outer context
this.set('value', 'cat');

await render(hbs`{{number}}`);

assert.strictEqual(number, 1)
});

test.skip('example with skip', async function (assert) {
// setup the outer context
this.set('value', 'cat');

await render(hbs`{{number}}`);

assert.ok(this.get('value'));
});

test.skip('example with skip w/o callback');

test.todo('example with todo', async function (assert) {
// setup the outer context
this.set('value', 'cat');

await render(hbs`{{number}}`);

assert.ok(this.get('value'));
});

test.todo('example with todo w/o callback');

test.only('example with only', async function (assert) {
// setup the outer context
this.set('value', 'cat');

await render(hbs`{{number}}`);

assert.ok(this.get('value'));
});
})

0 comments on commit 11cfab8

Please sign in to comment.