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 98b4637f
authored
Jan 13, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1245 from saschagehlich/bugfix/customeventemitter-fix
Fix CustomEventEmitter
2 parents
3132a570
886adc89
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
lib/emitters/custom-event-emitter.js
test/dao.test.js
test/emitters/custom-event-emitter.test.js
lib/emitters/custom-event-emitter.js
View file @
98b4637
...
@@ -36,12 +36,26 @@ module.exports = (function() {
...
@@ -36,12 +36,26 @@ module.exports = (function() {
// No error listener
// No error listener
var
er
=
arguments
[
1
];
var
er
=
arguments
[
1
];
// If error argument is an object but no error,
// boil it down to the value of the first key
// (probably an Array in most cases)
if
(
Utils
.
_
.
isObject
(
er
)
&&
!
(
er
instanceof
Error
))
{
er
=
er
[
Object
.
keys
(
er
)[
0
]]
}
// If error argument is an array, make sure we
// If error argument is an array, make sure we
// pass only the first error to the original
// pass only the first error to the original
// .emit() function of EventEmitter
// .emit() function of EventEmitter
if
(
er
instanceof
Array
)
{
if
(
er
instanceof
Array
)
{
arguments
[
1
]
=
Utils
.
_
.
flatten
(
er
)[
0
]
er
=
Utils
.
_
.
flatten
(
er
)[
0
]
}
}
// We don't want to throw strings. Make them Errors!
if
(
typeof
er
===
"string"
)
{
er
=
new
Error
(
er
)
}
arguments
[
1
]
=
er
}
}
EventEmitter
.
prototype
.
emit
.
apply
(
this
,
arguments
);
EventEmitter
.
prototype
.
emit
.
apply
(
this
,
arguments
);
...
...
test/dao.test.js
View file @
98b4637
...
@@ -710,7 +710,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -710,7 +710,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
})
})
it
(
"gets triggered if everything was ok"
,
function
(
done
)
{
it
(
"gets triggered if everything was ok"
,
function
(
done
)
{
this
.
User
.
count
().
complete
(
function
(
err
,
result
)
{
this
.
User
.
count
().
complete
(
function
(
err
,
result
)
{
expect
(
err
).
to
.
be
.
null
expect
(
err
).
to
.
be
.
null
expect
(
result
).
to
.
exist
expect
(
result
).
to
.
exist
...
...
test/emitters/custom-event-emitter.test.js
View file @
98b4637
...
@@ -102,4 +102,22 @@ describe(Support.getTestDialectTeaser("CustomEventEmitter"), function () {
...
@@ -102,4 +102,22 @@ describe(Support.getTestDialectTeaser("CustomEventEmitter"), function () {
})
})
})
})
})
})
describe
(
"when emitting an error event with a hash containing arrays of error strings"
,
function
()
{
describe
(
"if no error handler is given"
,
function
()
{
it
(
"should throw an error with the first error string"
,
function
(
done
)
{
var
emitter
=
new
CustomEventEmitter
()
var
errors
=
{
myValidation
:
[
"Invalid Length"
],
someOtherValidation
:
[
"Naah don't like that value!"
,
"It's weird, u know?"
]
}
expect
(
function
()
{
emitter
.
emit
(
"error"
,
errors
)
}).
to
.
throw
(
errors
.
myValidation
[
0
])
done
()
})
})
})
})
})
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