Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
857a1d31
Commit
857a1d31
authored
Apr 27, 2017
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some test cases for the same loop promise.
parent
17329edc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
137 additions
and
0 deletions
+137
-0
same-loop-promise.test.js
test/unit/same-loop-promise.test.js
+137
-0
No files found.
test/unit/same-loop-promise.test.js
0 → 100644
View file @
857a1d31
/* global describe, it, expect */
import
{
SameLoopPromise
}
from
'../../dist/lib/dynamic'
describe
(
'SameLoopPromise'
,
()
=>
{
describe
(
'basic api'
,
()
=>
{
it
(
'should support basic promise resolving'
,
(
done
)
=>
{
const
promise
=
new
SameLoopPromise
((
resolve
)
=>
{
setTimeout
(()
=>
{
resolve
(
1000
)
},
100
)
})
promise
.
then
((
value
)
=>
{
expect
(
value
).
toBe
(
1000
)
done
()
})
})
it
(
'should support resolving in the same loop'
,
()
=>
{
let
gotValue
=
null
const
promise
=
new
SameLoopPromise
((
resolve
)
=>
{
resolve
(
1000
)
})
promise
.
then
((
value
)
=>
{
gotValue
=
value
})
expect
(
gotValue
).
toBe
(
1000
)
})
it
(
'should support basic promise rejecting'
,
(
done
)
=>
{
const
error
=
new
Error
(
'Hello Error'
)
const
promise
=
new
SameLoopPromise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
reject
(
error
)
},
100
)
})
promise
.
catch
((
err
)
=>
{
expect
(
err
).
toBe
(
error
)
done
()
})
})
it
(
'should support rejecting in the same loop'
,
()
=>
{
const
error
=
new
Error
(
'Hello Error'
)
let
gotError
=
null
const
promise
=
new
SameLoopPromise
((
resolve
,
reject
)
=>
{
reject
(
error
)
})
promise
.
catch
((
err
)
=>
{
gotError
=
err
})
expect
(
gotError
).
toBe
(
error
)
})
})
describe
(
'complex usage'
,
()
=>
{
it
(
'should support a chain of promises'
,
(
done
)
=>
{
const
promise
=
new
SameLoopPromise
((
resolve
)
=>
{
setTimeout
(()
=>
{
resolve
(
1000
)
},
100
)
})
promise
.
then
((
value
)
=>
value
*
2
)
.
then
((
value
)
=>
value
+
10
)
.
then
((
value
)
=>
{
expect
(
value
).
toBe
(
2010
)
done
()
})
})
it
(
'should handle the error inside the then'
,
(
done
)
=>
{
const
error
=
new
Error
(
'1000'
)
const
promise
=
new
SameLoopPromise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
reject
(
error
)
},
100
)
})
promise
.
then
(
()
=>
4000
,
(
err
)
=>
parseInt
(
err
.
message
)
)
.
then
((
value
)
=>
value
+
10
)
.
then
((
value
)
=>
{
expect
(
value
).
toBe
(
1010
)
done
()
})
})
it
(
'should catch the error at the end'
,
(
done
)
=>
{
const
error
=
new
Error
(
'1000'
)
const
promise
=
new
SameLoopPromise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
reject
(
error
)
},
100
)
})
promise
.
then
((
value
)
=>
value
*
2
)
.
then
((
value
)
=>
value
+
10
)
.
catch
((
err
)
=>
{
expect
(
err
).
toBe
(
error
)
done
()
})
})
it
(
'should catch and proceed'
,
(
done
)
=>
{
const
error
=
new
Error
(
'1000'
)
const
promise
=
new
SameLoopPromise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
reject
(
error
)
},
100
)
})
promise
.
then
((
value
)
=>
value
*
2
)
.
then
((
value
)
=>
value
+
10
)
.
catch
((
err
)
=>
{
expect
(
err
).
toBe
(
error
)
return
5000
})
.
then
((
value
)
=>
{
expect
(
value
).
toBe
(
5000
)
done
()
})
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment