-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(suite): improve the typing of the pickAndPrepareFrameProps() an…
…d fix type / code error
- Loading branch information
1 parent
7d99f54
commit 38f269b
Showing
4 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { makePropsTransient } from './transientProps'; | ||
|
||
describe('frameprops', () => { | ||
describe('type tests', () => { | ||
it('should return the same keys just with the $ prefix as type', () => { | ||
const result: { | ||
$a: 1; | ||
$b: 2; | ||
} = makePropsTransient({ a: 1, b: 2 } as const); | ||
expect(result).toEqual({ | ||
$a: 1, | ||
$b: 2, | ||
}); | ||
}); | ||
|
||
it('should correctly be able to pick individual key', () => { | ||
const result: { | ||
$a: 1; | ||
$b: 2; | ||
} = makePropsTransient({ a: 1, b: 2 } as const); | ||
|
||
const a = result.$a; | ||
expect(a).toEqual(1); | ||
}); | ||
|
||
it('should throw a type error when the resulting object is not assigned to a variable with a $ prefix', () => { | ||
// @ts-expect-error: here should be $ prefix for the key | ||
const result: { | ||
a: 1; | ||
$b: 2; | ||
} = makePropsTransient({ a: 1, b: 2 } as const); | ||
expect(result).toEqual({ | ||
$a: 1, | ||
$b: 2, | ||
}); | ||
}); | ||
it('should throw a type error when trying to get the key that is not specified in the argument object', () => { | ||
// @ts-expect-error: c is not a key of the object | ||
const result: { | ||
$c: 1; | ||
} = makePropsTransient({ a: 1, b: 2 } as const); | ||
expect(result).toEqual({ | ||
$a: 1, | ||
$b: 2, | ||
}); | ||
}); | ||
|
||
it('should throw a type error when trying to access a key without a $ prefix', () => { | ||
const result: { | ||
$a: 1; | ||
$b: 2; | ||
} = makePropsTransient({ a: 1, b: 2 } as const); | ||
|
||
// @ts-expect-error: here should be $ prefix for the key | ||
const { a } = result; | ||
expect(a).toEqual(undefined); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { makePropsTransient } from './transientProps'; | ||
|
||
describe('transientProps', () => { | ||
describe('type tests', () => { | ||
it('should return the same keys just with the $ prefix as type', () => { | ||
const result: { | ||
$a: 1; | ||
$b: 2; | ||
} = makePropsTransient({ a: 1, b: 2 } as const); | ||
expect(result).toEqual({ | ||
$a: 1, | ||
$b: 2, | ||
}); | ||
}); | ||
|
||
it("should should throw an a type error when there isn't a property with a $ prefix", () => { | ||
// @ts-expect-error: here should be $ prefixes for the keys | ||
const result: { | ||
a: 1; | ||
b: 2; | ||
} = makePropsTransient({ a: 1, b: 2 } as const); | ||
expect(result).toEqual({ | ||
$a: 1, | ||
$b: 2, | ||
}); | ||
}); | ||
}); | ||
}); |