-
Notifications
You must be signed in to change notification settings - Fork 650
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
test: setup TypeScript settings #824
base: alpha
Are you sure you want to change the base?
Changes from all commits
d05136a
168d733
ab60306
a1288b5
ac171df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
env: | ||
jest: true | ||
es6: true | ||
rules: | ||
no-require: off | ||
global-require: off | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
let React; | ||
let ChildMapping; | ||
import React from 'react'; | ||
import * as ChildMapping from '../src/utils/ChildMapping'; | ||
|
||
describe('ChildMapping', () => { | ||
beforeEach(() => { | ||
React = require('react'); | ||
ChildMapping = require('../src/utils/ChildMapping'); | ||
}); | ||
|
||
it('should support getChildMapping', () => { | ||
let oneone = <div key="oneone" />; | ||
let onetwo = <div key="onetwo" />; | ||
|
@@ -32,102 +27,102 @@ describe('ChildMapping', () => { | |
|
||
it('should support mergeChildMappings for adding keys', () => { | ||
let prev = { | ||
one: true, | ||
two: true, | ||
one: 'one', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like runtime behavior changed. But the PR title says it's only about test. Could you clarify why this change here is necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure but that's not a reason to change runtime behavior, no? So far this looks like a breaking change just so that our tests are type-checked? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "runtime behavior" mean? This doesn't change any runtime behavior. The TypeScript migration causes this change. Do you mean that we shouldn't do any incompatible changes with DefinitelyTyped? |
||
two: 'two', | ||
}; | ||
let next = { | ||
one: true, | ||
two: true, | ||
three: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
}; | ||
expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ | ||
one: true, | ||
two: true, | ||
three: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
}); | ||
}); | ||
|
||
it('should support mergeChildMappings for removing keys', () => { | ||
let prev = { | ||
one: true, | ||
two: true, | ||
three: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
}; | ||
let next = { | ||
one: true, | ||
two: true, | ||
one: 'one', | ||
two: 'two', | ||
}; | ||
expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ | ||
one: true, | ||
two: true, | ||
three: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
}); | ||
}); | ||
|
||
it('should support mergeChildMappings for adding and removing', () => { | ||
let prev = { | ||
one: true, | ||
two: true, | ||
three: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
}; | ||
let next = { | ||
one: true, | ||
two: true, | ||
four: true, | ||
one: 'one', | ||
two: 'two', | ||
four: 'four', | ||
}; | ||
expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ | ||
one: true, | ||
two: true, | ||
three: true, | ||
four: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
four: 'four', | ||
}); | ||
}); | ||
|
||
it('should reconcile overlapping insertions and deletions', () => { | ||
let prev = { | ||
one: true, | ||
two: true, | ||
four: true, | ||
five: true, | ||
one: 'one', | ||
two: 'two', | ||
four: 'four', | ||
five: 'five', | ||
}; | ||
let next = { | ||
one: true, | ||
two: true, | ||
three: true, | ||
five: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
five: 'five', | ||
}; | ||
expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ | ||
one: true, | ||
two: true, | ||
three: true, | ||
four: true, | ||
five: true, | ||
one: 'one', | ||
two: 'two', | ||
three: 'three', | ||
four: 'four', | ||
five: 'five', | ||
}); | ||
}); | ||
|
||
it('should support mergeChildMappings with undefined input', () => { | ||
let prev = { | ||
one: true, | ||
two: true, | ||
const prev = { | ||
one: 'one', | ||
two: 'two', | ||
}; | ||
|
||
let next; | ||
const next = undefined; | ||
|
||
expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ | ||
one: true, | ||
two: true, | ||
one: 'one', | ||
two: 'two', | ||
}); | ||
|
||
prev = undefined; | ||
const prev2 = undefined; | ||
|
||
next = { | ||
three: true, | ||
four: true, | ||
const next2 = { | ||
three: 'three', | ||
four: 'four', | ||
}; | ||
|
||
expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ | ||
three: true, | ||
four: true, | ||
expect(ChildMapping.mergeChildMappings(prev2, next2)).toEqual({ | ||
three: 'three', | ||
four: 'four', | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-ignore | ||
global.requestAnimationFrame = function (callback) { | ||
setTimeout(callback, 0); | ||
}; |
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.
Not really a fan of TypeScript in runtime tests precisely because runtime tests are annoying to type. The previous test did work differently by clearing modules for each test. A static import is not the same.
If you want to test the types, we should have separate test files for them.
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.
Yeah, but this seems not to be necessary because the tests don't mock anything or mutate modules. I prefer not to mock or mutate modules as possible. So it would be nice to use static imports as default.
That is a valid opinion, but I'd like to write tests in TypeScript. If typing test code is annoying, we can use
any
or type casting in that places.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.
We're doing neither here. We're resetting the module which is not yet supported with Jest and ESM. So until then, we need to re-require.
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.
Thank you, I have two questions.
tsc
?