Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit c8c76d43
authored
Mar 22, 2021
by
Constantin Metz
Committed by
GitHub
Mar 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(types): add tests for `.previous` and `.set` (#13129)
1 parent
de5f21dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
3 deletions
types/test/define.ts
types/test/model.ts
types/test/define.ts
View file @
c8c76d4
...
...
@@ -27,7 +27,7 @@ const User = sequelize.define<UserModel>(
);
async
function
test
()
{
expectTypeOf
<
UserModel
>
().
toMatchTypeOf
(
new
User
());
expectTypeOf
<
UserModel
>
().
toMatchTypeOf
(
User
.
build
());
const
user
=
await
User
.
findOne
();
expectTypeOf
(
user
).
toEqualTypeOf
<
UserModel
|
null
>
();
...
...
@@ -60,7 +60,7 @@ UntypedUser.customStaticMethod = () => {};
async
function
testUntyped
()
{
UntypedUser
.
customStaticMethod
();
expectTypeOf
<
UntypedUserModel
>
().
toMatchTypeOf
(
new
UntypedUser
());
expectTypeOf
<
UntypedUserModel
>
().
toMatchTypeOf
(
UntypedUser
.
build
());
const
user
=
await
UntypedUser
.
findOne
();
expectTypeOf
(
user
).
toEqualTypeOf
<
UntypedUserModel
|
null
>
();
...
...
types/test/model.ts
View file @
c8c76d4
import
{
expectTypeOf
}
from
"expect-type"
;
import
{
Association
,
BelongsToManyGetAssociationsMixin
,
DataTypes
,
HasOne
,
Model
,
Sequelize
}
from
'sequelize'
;
import
{
Association
,
BelongsToManyGetAssociationsMixin
,
DataTypes
,
HasOne
,
Model
,
Optional
,
Sequelize
}
from
'sequelize'
;
import
{
ModelDefined
}
from
'../lib/model'
;
expectTypeOf
<
HasOne
>
().
toMatchTypeOf
<
Association
>
();
class
MyModel
extends
Model
{
...
...
@@ -151,3 +152,35 @@ Actor.belongsToMany(Film, {
paranoid
:
true
}
});
interface
ModelAttributes
{
id
:
number
;
name
:
string
;
}
interface
CreationAttributes
extends
Optional
<
ModelAttributes
,
'id'
>
{}
const
ModelWithAttributes
:
ModelDefined
<
ModelAttributes
,
CreationAttributes
>
=
sequelize
.
define
(
'efs'
,
{
name
:
DataTypes
.
STRING
});
const
modelWithAttributes
=
ModelWithAttributes
.
build
();
/**
* Tests for set() type
*/
expectTypeOf
(
modelWithAttributes
.
set
).
toBeFunction
();
expectTypeOf
(
modelWithAttributes
.
set
).
parameter
(
0
).
toEqualTypeOf
<
Partial
<
ModelAttributes
>>
();
/**
* Tests for previous() type
*/
expectTypeOf
(
modelWithAttributes
.
previous
).
toBeFunction
();
expectTypeOf
(
modelWithAttributes
.
previous
).
toBeCallableWith
(
'name'
);
expectTypeOf
(
modelWithAttributes
.
previous
).
parameter
(
0
).
toEqualTypeOf
<
keyof
ModelAttributes
>
();
expectTypeOf
(
modelWithAttributes
.
previous
).
parameter
(
0
).
not
.
toEqualTypeOf
<
'unreferencedAttribute'
>
();
expectTypeOf
(
modelWithAttributes
.
previous
).
returns
.
toEqualTypeOf
<
string
|
number
|
undefined
>
();
expectTypeOf
(
modelWithAttributes
.
previous
(
'name'
)).
toEqualTypeOf
<
string
|
undefined
>
();
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment