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 9c05b269
authored
Sep 20, 2014
by
overlookmotel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for promises in hooks
1 parent
97f4a7ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
10 deletions
test/hooks.test.js
test/hooks.test.js
View file @
9c05b26
...
@@ -5267,20 +5267,39 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
...
@@ -5267,20 +5267,39 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
return
this
.
User
.
sync
({
force
:
true
})
return
this
.
User
.
sync
({
force
:
true
})
})
})
it
(
'can return a promise
and modify fields
'
,
function
()
{
it
(
'can return a promise'
,
function
()
{
var
self
=
this
var
self
=
this
,
hookRun
=
false
this
.
User
.
beforeBulkCreate
(
function
(
daos
,
fields
)
{
this
.
User
.
beforeBulkCreate
(
function
(
daos
,
options
)
{
return
self
.
sequelize
.
Promise
.
resolve
([
daos
,
[
'username'
]])
hookRun
=
true
return
self
.
sequelize
.
Promise
.
resolve
()
})
})
return
this
.
User
.
bulkCreate
([
return
this
.
User
.
bulkCreate
([
{
username
:
'Bob'
,
mood
:
'
cold
'
},
{
username
:
'Bob'
,
mood
:
'
happy
'
},
{
username
:
'Tobi'
,
mood
:
'
hot
'
}
{
username
:
'Tobi'
,
mood
:
'
sad
'
}
],
{
fields
:
[],
individualHooks
:
false
}).
success
(
function
(
bulkUsers
)
{
],
{
individualHooks
:
false
}).
success
(
function
(
bulkUsers
)
{
return
self
.
User
.
all
().
success
(
function
(
users
)
{
return
self
.
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
[
0
].
mood
).
to
.
equal
(
null
)
expect
(
hookRun
).
to
.
equal
(
true
)
expect
(
users
[
1
].
mood
).
to
.
equal
(
null
)
})
})
})
it
(
'can return undefined'
,
function
()
{
var
self
=
this
,
hookRun
=
false
this
.
User
.
beforeBulkCreate
(
function
(
daos
,
options
)
{
hookRun
=
true
})
return
this
.
User
.
bulkCreate
([
{
username
:
'Bob'
,
mood
:
'happy'
},
{
username
:
'Tobi'
,
mood
:
'sad'
}
],
{
individualHooks
:
false
}).
success
(
function
(
bulkUsers
)
{
return
self
.
User
.
all
().
success
(
function
(
users
)
{
expect
(
hookRun
).
to
.
equal
(
true
)
})
})
})
})
})
})
...
@@ -5289,11 +5308,23 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
...
@@ -5289,11 +5308,23 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
var
self
=
this
var
self
=
this
this
.
User
.
beforeCreate
(
function
()
{
this
.
User
.
beforeCreate
(
function
()
{
return
self
.
sequelize
.
Utils
.
Promise
.
reject
(
"I'm afraid I can't let you do that"
);
return
self
.
sequelize
.
Utils
.
Promise
.
reject
(
new
Error
(
"I'm afraid I can't let you do that"
));
})
return
this
.
User
.
create
({}).
catch
(
function
(
err
)
{
expect
(
err
.
message
).
to
.
equal
(
"I'm afraid I can't let you do that"
)
})
})
it
(
'can return an error by throwing'
,
function
()
{
var
self
=
this
this
.
User
.
beforeCreate
(
function
()
{
throw
(
new
Error
(
"I'm afraid I can't let you do that"
));
})
})
return
this
.
User
.
create
({}).
catch
(
function
(
err
)
{
return
this
.
User
.
create
({}).
catch
(
function
(
err
)
{
expect
(
err
).
to
.
equal
(
"I'm afraid I can't let you do that"
)
expect
(
err
.
message
).
to
.
equal
(
"I'm afraid I can't let you do that"
)
})
})
})
})
})
})
...
...
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