-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduced TypeScript (Part 4) #120
Conversation
1cf7aa9
to
d551e6f
Compare
c18fba2
to
1266a9d
Compare
export interface CustomAssert extends Assert { | ||
areDataAttributesCorrect?: (dataAttributes: DataAttributes) => void; | ||
areDimensionsCorrect?: ( | ||
expectedWidth: number, | ||
expectedHeight: number | ||
) => void; | ||
areFeaturesCorrect?: (features: Features) => void; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find online an example of how to type custom assertions. By trial and error, I came up with this interface. The ?:
was needed for the delete
operator not to cause a TypeScript error.
import EmberResolver from 'ember-resolver'; | ||
|
||
interface SetupTestOptions { | ||
resolver?: EmberResolver | undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default async function takeSnapshot(qunitAssert, options = {}) { | ||
checkInput(qunitAssert, options); | ||
export default async function takeSnapshot( | ||
qunitAssert: unknown, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow, the assert
object, which originally should be of type Assert
(from qunit
, possibly extended by qunit-dom
), is transformed into an object whose type definition I couldn't find:
I thought it'd be best to specify the type as unknown
, then cast it into something (called QUnitAssert
here) before we pass it to getName()
.
assert( | ||
"`qunitAssert` must be QUnit's assert object.", | ||
typeof qunitAssert === 'object' && !!qunitAssert.test | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted these lines because I shouldn't have tested a third-party's internal implementation.
this.fetchData = () => { | ||
assert.ok( | ||
true, | ||
'{{did-insert}} modifier works. (But we should find a better way to separate concerns!)' | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes the test being dependent on @ember/render-modifiers
to have been installed.
@@ -5,6 +5,7 @@ import { setRunOptions } from 'ember-a11y-testing/test-support'; | |||
import { start } from 'ember-qunit'; | |||
import * as QUnit from 'qunit'; | |||
import { setup } from 'qunit-dom'; | |||
import 'qunit-dom'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qunit-dom
suggested (at the time of writing) adding this import statement so that assert
takes the correct type (i.e. assert.dom
becomes well-defined).
Description
The demo app, which is heavily used for testing
ember-container-query
, is a fairly complex Ember application. To help onboard contributors, I'd like to introduce TypeScript to better document code.Rather than converting the entire demo app to TypeScript at once (which would result in a large pull request that's hard to understand when we go back to), I'll split the task into a few.
In Part 4, JavaScript files in the following directories have been converted to TypeScript:
tests/acceptance
tests/helpers
tests/integration
tests/unit
Notes
Over 80%!
References